Unity 编辑器 Inspector
1 using UnityEngine; 2 using System.Collections.Generic; 3 using System; 4 public class TestA : MonoBehaviour 5 { 6 public int T_int = 1; 7 public int[] TA_int = new int[] { 1, 2 }; 8 public long T_long = 2; 9 public float T_float = 3; 10 public string T_String = "5"; 11 public Transform T_Transform; 12 public Vector3 T_Vector3 = new Vector3(1, 1, 1); 13 public List<Vector3> TL_Vector3 = new List<Vector3>(); 14 public ETest T_Enum = ETest.T1; 15 [SerializeField] 16 public MClass T_class; 17 18 public enum ETest 19 { 20 Null = 0, 21 T1, 22 T2, 23 T3 24 } 25 } 26 [Serializable] 27 public class MClass 28 { 29 public int T_int = 1; 30 public string T_String = "12"; 31 public Transform T_Transform; 32 }
using UnityEngine; using UnityEditor; [CustomEditor(typeof(TestA))] public class TestAEditor : Editor { public override void OnInspectorGUI() { TestA t = target as TestA; var so = new SerializedObject(target); so.Update(); t.T_int = EditorGUILayout.IntField("整形", t.T_int); var ctai = so.FindProperty("TA_int"); EditorGUILayout.PropertyField(ctai, new GUIContent("整形数组([])"), true); t.T_long = EditorGUILayout.LongField("长整形", t.T_long); t.T_float = EditorGUILayout.FloatField("浮点形", t.T_float); t.T_String = EditorGUILayout.TextField("字符串", t.T_String); t.T_Transform = (Transform)EditorGUILayout.ObjectField("组件", t.T_Transform, typeof(Transform), true) as Transform; t.T_Vector3 = EditorGUILayout.Vector3Field("向量", t.T_Vector3); var ctav = so.FindProperty("TL_Vector3"); EditorGUILayout.PropertyField(ctav, new GUIContent("向量数组(List)"), true); t.T_Enum = (TestA.ETest)EditorGUILayout.EnumPopup("单项选择枚举", t.T_Enum); var mClass = so.FindProperty("T_class"); EditorGUILayout.PropertyField(mClass,new GUIContent("序列化类"),true); so.ApplyModifiedProperties(); } }