一.创建脚本路径
创建脚本路径不再限制 一般写在自定义组件类的下边
二.特性
CustomEditor 定义主设计图面由自定义代码实现数组的编辑器。
两个构造函数
1.public CustomEditor(Type inspectedType);
2.public CustomEditor(Type inspectedType, bool editorForChildClasses);
参数意义:
inspectedType:自定义哪个类型的Inspector面板
editorForChildClasses:inspectedType的子类是否使用这个自定义Inspector面板 默认为false
三.示例
using UnityEditor;
using UnityEngine;
public class PlayerView : MonoBehaviour {
public Transform tf;
void Start() {
}
void Update() {
}
}
[CustomEditor(typeof(PlayerView))]
public class PlayerViewEditor : Editor {
private void OnEnable() {
}
public override void OnInspectorGUI() {
base.OnInspectorGUI();
EditorGUILayout.BeginHorizontal();
if(GUILayout.Button("Test")) {
Debug.Log("XXX");
}
EditorGUILayout.EndHorizontal();
}
}
后续将逐渐讲解编辑面板所使用到的类和方法,此处不做赘述
以上定义了PlayerView类的Inspector面板
如图:
点击Test按钮
![[架构之路-118]-《软考-系统架构设计师》-软架构设计-11-可靠性相关设计](https://img-blog.csdnimg.cn/img_convert/67318a1bf19557e7f77cfb31ecae4a14.png)














![[零刻] SER5 Pro 迷你主机:从开箱到安装ESXi+虚拟机](https://img-blog.csdnimg.cn/img_convert/49de939fdff07d23062b5a159f461c79.png)



