今天第一次自定义编辑器,记录一下心得。
1.在Editor文件夹下建立一个脚本,将此脚本与想自定义编辑器的脚本绑定
2.在OnEnable()方法中获取原脚本中,需要操作的对象。
3.OnInspectorGUI()中,EditorGUILayout.PropertyField(Enemy);方法的先后顺序,决定了编辑器中排列的先后顺序。
4.如果需要下拉菜单,请定义枚举类型
5.最后,不要忘了test.ApplyModifiedProperties();将之前的代码应用。
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(EnemyAI))]//关联修改的脚本
public class NewBehaviourScript1 : Editor
{
//序列化
private SerializedObject test;
//各个公开变量
public SerializedProperty Enemy;
private SerializedProperty Player;
private SerializedProperty ChooseEnemyPattern;
private SerializedProperty ChooseEnemyType;
private SerializedProperty PatrolA;
private SerializedProperty PatrolB;
private SerializedProperty LaserTX;
private SerializedProperty ATInterval;
private SerializedProperty EnemyAttackRange;
private SerializedProperty EnemyMoveSpeed;
pr