[Unity编辑器]与编辑器相关的属性与类
来源:互联网 发布:simpson算法流程图 编辑:程序博客网 时间:2024/05/21 15:49
一、MenuItem
点击My Window时调用Init()
二、RequireComponent
添加脚本A时自动添加刚体组件
三、AddComponentMenu
当按下脚本A时,为当前选择的GameObject添加脚本A
四、ContextMenu
按下Test时,执行Test()
五、自定义Attribute属性
using UnityEngine;using System.Collections;public class TestAttribute : MonoBehaviour { [Range(0, 10)] public int a; [MyRange(-5f, 5f)] public float b; public enum Force {蜀国,吴国,魏国}; [MyEnum] public Force force;//多选}
using UnityEngine;using System.Collections;public class MyRange : PropertyAttribute { public float min; public float max; public MyRange(float min, float max) { this.min = min; this.max = max; }}
using UnityEngine;using System.Collections;using UnityEditor;[CustomPropertyDrawer(typeof(MyRange))]public class MyRangeDrawer : PropertyDrawer { public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { MyRange myRange = attribute as MyRange; if (property.propertyType == SerializedPropertyType.Float) EditorGUI.Slider(position, property, myRange.min, myRange.max, label); else if (property.propertyType == SerializedPropertyType.Integer) EditorGUI.IntSlider(position, property, (int)myRange.min, (int)myRange.max, label); }}
using UnityEngine;using System.Collections;public class MyEnum : PropertyAttribute {}
using UnityEngine;using System.Collections;using UnityEditor;[CustomPropertyDrawer(typeof(MyEnum))]public class MyEnumDrawer : PropertyDrawer { public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { property.intValue = EditorGUI.MaskField(position,label,property.intValue,property.enumNames); }}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using UnityEngine;using UnityEditor;using System.IO;/// <summary>/// 需要创建Editor文件夹并把此类放进去/// 操作文件的相关类:/// Directory 提供操作目录的静态方法/// DirectoryInfo 提供操作目录的实例方法/// File 提供操作文件的静态方法/// FileInfo 提供操作文件的实例方法/// Path 操作路径/// /// Selection/// AssetDatabase/// 各种Importer/// SerializedObject 与 SerializedProperty:/// http://blog.csdn.net/qinyuanpei/article/details/49120765/// http://www.manew.com/thread-46528-1-1.html?_dsign=4fc09684/// </summary>public class TestEditor { static string dataPath = Application.dataPath + "/A"; static string outputPath = Application.dataPath + "/B"; [MenuItem("Window/OperateFile")] static void OperateFile() { if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); FileStream fs = File.Create(dataPath + "/a.txt"); fs.Close(); } DirectoryInfo di = new DirectoryInfo(outputPath); if (!di.Exists) { di = new DirectoryInfo(outputPath); di.Create(); FileInfo fi = new FileInfo(outputPath + "/b.txt"); fi.Create(); } //返回目录中所有以.txt结尾的文件的完整路径 string[] dataPaths = Directory.GetFiles(dataPath, "*.txt"); if (dataPaths != null) { for (int i = 0; i < dataPaths.Length; i++) { string s = Path.GetFileNameWithoutExtension(dataPaths[i]); File.WriteAllText(dataPaths[i], s); Debug.Log(File.ReadAllText(dataPaths[i])); } } Debug.Log("finish"); AssetDatabase.Refresh(); } [MenuItem("Window/MultiplyModify")] static void MultiplyModify() { Object[] o = Selection.GetFiltered(typeof(Texture), SelectionMode.DeepAssets); foreach (Texture s in o) { string path = AssetDatabase.GetAssetPath(s); TextureImporter textureImporter = TextureImporter.GetAtPath(path) as TextureImporter; textureImporter.textureType = TextureImporterType.Sprite; AssetDatabase.ImportAsset(path); } } //右键菜单 [MenuItem("Assets/DebugPath")] static void DebugPath() { for (int i = 0; i < Selection.objects.Length; i++) { Debug.Log(AssetDatabase.GetAssetPath(Selection.objects[i])); } }}
0 0
- [Unity编辑器]与编辑器相关的属性与类
- [Unity编辑器]与编辑器相关的属性与类
- 与编辑器相关的IEditorInput
- [Unity编辑器]编辑器与序列化
- 【Unity】编辑器属性
- Unity属性窗口编辑器
- Delphi组件与属性编辑器
- Delphi组件与属性编辑器
- 整理Unity 编辑器的相关知识
- unity编辑器对对象属性的编辑
- Unity应用基础之编辑器与界面
- unity 自定义编辑器 枚举 隐藏与显示
- unity 扩展编辑器 文件操作时常用的类与方法
- 【Unity编辑器】Unity基于模板生成代码的原理与应用
- Unity的编辑器使用
- Unity编辑器的使用
- Linux的编译器与编辑器
- 【Spring 基础篇三】属性注入与属性编辑器
- Spring AOP (二)
- Java this 关键字用法
- Chomp game博弈游戏
- Team Explorer使用教程3
- sencha touch自定义messageBox
- [Unity编辑器]与编辑器相关的属性与类
- MeasureSpec的简单说明
- hdu3278 Puzzle
- Debug版本的Dll可以正常工作,Release版本却提示找不到dll
- Activity 切换动画(小米图库列表进入详情页,图片从固定位置放大进入,缩小退出)
- (4.1.26)ContentProvider和Uri详解
- Mongo地理位置索引原理
- 图片延时加载例子详解
- (4.1.26.1)ContentProvider案例