今天第一次自定义编辑器,记录一下心得。
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

本文介绍了在Unity3D 2017.3版本中自定义编辑器的过程,包括在Editor文件夹下创建脚本,OnEnable方法获取对象,通过OnInspectorGUI调整显示顺序,使用枚举创建下拉菜单,并强调了test.ApplyModifiedProperties()的重要性。
最低0.47元/天 解锁文章
2972

被折叠的 条评论
为什么被折叠?



