using UnityEngine; using UnityEditor.UI; using UnityEditor; using XRTool.Util; namespace XRTool.WorldUI { [InitializeOnLoad] [CustomEditor(typeof(XRToggle))] public class XRToggleEditor : ToggleEditor { private XRToggle toggle; private SerializedProperty openPos; private SerializedProperty moveTime; private bool isCheckBox = false; private bool isSwitch; [MenuItem("GameObject/XRUI/XRToggle/XRToggle_CheckBox", priority = 0)] static void Init() { UnityLog.Instance.Log(typeof(XRToggle).Name + "_CheckBox"); var obj = Instantiate(Resources.Load(typeof(XRToggle).Name + "_CheckBox")); obj.name = (typeof(XRToggle).Name + "_CheckBox"); if (obj) { var parent = Selection.activeGameObject; if (!parent) { var canvas = GameObject.FindObjectsOfType(typeof(Canvas)); if (canvas != null) { for (int i = 0; i < canvas.Length; i++) { if ((canvas[i] as Canvas).renderMode == RenderMode.WorldSpace) { parent = (canvas[i] as Canvas).gameObject; break; } } } } UnityUtil.SetParent(parent ? parent.transform : null, obj.transform); Selection.activeGameObject = obj.gameObject; } } [MenuItem("GameObject/XRUI/XRToggle/XRToggle_Switch", priority = 0)] static void Init_Switch() { var obj = Instantiate(Resources.Load(typeof(XRToggle).Name + "_Switch")); obj.name = (typeof(XRToggle).Name + "_Switch"); if (obj) { var parent = Selection.activeGameObject; if (!parent) { var canvas = GameObject.FindObjectsOfType(typeof(Canvas)); if (canvas != null) { for (int i = 0; i < canvas.Length; i++) { if ((canvas[i] as Canvas).renderMode == RenderMode.WorldSpace) { parent = (canvas[i] as Canvas).gameObject; break; } } } } UnityUtil.SetParent(parent ? parent.transform : null, obj.transform); Selection.activeGameObject = obj.gameObject; } } protected override void OnEnable() { base.OnEnable(); toggle = target as XRToggle; toggle.initListen(); openPos = serializedObject.FindProperty("openPos"); moveTime = serializedObject.FindProperty("moveTime"); isCheckBox = false; isSwitch = false ; if (toggle.name.Contains("CheckBox")) { isCheckBox = true; } if(toggle.name.Contains("Switch")) { isSwitch = true; } toggle.isHideCheck = isCheckBox; toggle.isSwitch = isSwitch; } /// /// /// public override void OnInspectorGUI() { base.OnInspectorGUI(); if (isSwitch) { EditorGUILayout.PropertyField(openPos, new GUIContent("位移")); EditorGUILayout.PropertyField(moveTime, new GUIContent("时间")); serializedObject.ApplyModifiedProperties(); if (GUI.changed) { } } } } }