赞
踩
- public class Test : MonoBehaviour
- {
- [HideInInspector]
- [Header("数量")]
- [SerializeField]
- public int num;
-
- [Header("分布类型")]
- [SerializeField]
- public DistributionType distType;
-
- [HideInInspector]
- [Header("位置")]
- [SerializeField]
- public List<Vector3> positions;
-
- [Header("test")]
- [SerializeField]
- List<testType> test;
- }
-
-
- [Serializable]
- public class testType
- {
- public int id;
- public string name;
- }
-
-
- public enum DistributionType
- {
- None,
- test1,
- test2,
- test3,
- }
- [CustomEditor(typeof(Test))]
- public class TestEditor : Editor {
-
- public SerializedObject obj;
-
- public SerializedProperty distType;
- public SerializedProperty positions;
- public SerializedProperty num;
- public SerializedProperty test;
-
- void OnEnable()
- {
- obj = new SerializedObject(target);
- distType = obj.FindProperty("distType");
- num = obj.FindProperty("num");
- positions = obj.FindProperty("positions");
-
- test = obj.FindProperty("test");
- }
-
- public override void OnInspectorGUI()
- {
- //base.OnInspectorGUI();
- obj.Update();
- if (distType.enumValueIndex == 0)
- {
- EditorGUILayout.PropertyField(positions, true);
- }
- else
- {
- EditorGUILayout.PropertyField(num);
- }
- EditorGUILayout.PropertyField(test,true);
- obj.ApplyModifiedProperties();
-
- }
- }
在数据类中(文中是Test类)数组类的字段在开启基类的base.OnInspectorGUI();不能用[HideInInspector],否则会无法显示数组内容。
参考链接:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。