using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; [CustomEditor(typeof(ScoreJudge_FixedValue))] //关联之前的脚本 public class ScoreJudge_FixedValueEditor : Editor { private SerializedObject obj; //序列化 private SerializedProperty oneValue, mybool, mybyte, myshort, myint, myfloat, mydouble, mystring, myvector3; //定义变量 void OnEnable() { obj = new SerializedObject(target); oneValue = obj.FindProperty("oneValueSyncObject"); mybool = obj.FindProperty("mybool"); mybyte = obj.FindProperty("mybyte"); myshort = obj.FindProperty("myshort"); myint = obj.FindProperty("myint"); myfloat = obj.FindProperty("myfloat"); mydouble = obj.FindProperty("mydouble"); mystring = obj.FindProperty("mystring"); myvector3 = obj.FindProperty("myvector3"); } public override void OnInspectorGUI() { base.OnInspectorGUI(); obj.Update(); //显示 EditorGUILayout.PropertyField(oneValue); OneValueSyncObject tmp= (OneValueSyncObject)(oneValue.objectReferenceValue); if (tmp != null) { switch (tmp.valueType) { case ValueType.Null: break; case ValueType.Bool: EditorGUILayout.PropertyField(mybool); break; case ValueType.Byte: EditorGUILayout.PropertyField(mybyte); break; case ValueType.Short: EditorGUILayout.PropertyField(myshort); break; case ValueType.Int: EditorGUILayout.PropertyField(myint); break; case ValueType.Float: EditorGUILayout.PropertyField(myfloat); break; case ValueType.Double: EditorGUILayout.PropertyField(mydouble); break; case ValueType.String: EditorGUILayout.PropertyField(mystring); break; case ValueType.Vector3: EditorGUILayout.PropertyField(myvector3); break; } } //应用 obj.ApplyModifiedProperties(); } }