using NUnit.Framework.Internal;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(DoorControl))]
public class DoorControlEditor : Editor
{
private SerializedObject obj;
private DoorControl doorControl;
private SerializedProperty iterator;
private List<string> propertyNames;
private DoorType tryGetValue;
private Dictionary<string, DoorType> specialPropertys
= new Dictionary<string, DoorType>
{
//表示字段a只会在枚举值=typeA时显示
{ "Vec", DoorType.ROTATE },
{ "Agent", DoorType.MOVE },
{ "Temp", DoorType.MOVE },
};
void OnEnable()
{
obj = new SerializedObject(target);
iterator = obj.GetIterator();
iterator.NextVisible(true);
propertyNames = new List<string>();
do
{
propertyNames.Add(iterator.name);
} while (iterator.NextVisible(false));
doorControl = (DoorControl)target;
}
public override void OnInspectorGUI()
{
obj.Update();
GUI.enabled = false;
foreach (var name in propertyNames)
{
if (specialPropertys.TryGetValue(name, out tryGetValue)
&& tryGetValue != doorControl.doorType)
continue;
EditorGUILayout.PropertyField(obj.FindProperty(name));
if (!GUI.enabled)//让第1次遍历到的 Script 属性为只读
GUI.enabled = true;
}
obj.ApplyModifiedProperties();
}
}
Unity Editor 不同枚举显示不同属性
猜你喜欢
转载自blog.csdn.net/weixin_46711336/article/details/128096974
今日推荐
周排行