1118OPSSNew/Assets/Editor/OneValueSyncEditor.cs

80 lines
2.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(OneValueSyncObject))] //关联之前的脚本
public class OneValueSyncEditor : Editor
{
private SerializedObject obj; //序列化
private SerializedProperty valuetype, mybool, mybyte, myshort, myint, myfloat, mydouble, mystring, myvector3; //定义变量
void OnEnable()
{
obj = new SerializedObject(target);
valuetype = obj.FindProperty("valueType");
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(valuetype);
ValueType tmp=(ValueType)valuetype.enumValueIndex;
switch (tmp)
{
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();
}
}