Unity编辑器拓展Editor类学习记录

官方文档:https://docs.unity3d.com/Manual/editor-CustomEditors.html

重写inspector面板首先得在类的最上方用
[CustomEditor(typeof(T))]
Unity编辑器拓展Editor类学习记录

T就是需要重写的对象类名(需要强转类型),这样重写后 挂上T脚本,inspector面板就是我们自己重写的效果了

如果需要在编辑模式下运行周期函数,那么需要加上
[ExecuteInEditMode]
Unity编辑器拓展Editor类学习记录
同时也可以把需要的某些方法放到inspector面板上
在某方法上使用
[ContextMenu(“Test”)] 引号内为展示时的名字
Unity编辑器拓展Editor类学习记录
Unity编辑器拓展Editor类学习记录
这样就可以直接运行了,当然也可以用GUILayout.Button在inspector面板上创建一个按钮来运行方法

下拉框展示枚举对象
枚举对象=(GameContent)EditorGUILayout.EnumPopup(“xxx”, 枚举对象);

普通下拉框
index= EditorGUILayout.Popup(index,string[]); index为下拉框下标,string[]为要展示的string数组
Unity编辑器拓展Editor类学习记录

button按钮
GUILayout.Button(“按钮”)

label文本框
GUILayout.Label("-------------------------------------------");
Unity编辑器拓展Editor类学习记录

GUILayout.BeginHorizontal();
使此处部分代码为在一行内
GUILayout.EndHorizontal();

GUILayout.BeginVertical();
使此处部分代码为在垂直一行内
GUILayout.EndVertical();

在Width上 空出x值的范围
EditorGUILayout.Space(int x);

创建一个可拖动事件框
EditorGUILayout.PropertyField(serialized.FindProperty(“unityEvent”));
serialized.ApplyModifiedProperties();
Unity编辑器拓展Editor类学习记录