123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- 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<XRToggle>(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<XRToggle>(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;
- }
- /// <summary>
- ///
- /// </summary>
- public override void OnInspectorGUI()
- {
- base.OnInspectorGUI();
- if (isSwitch)
- {
- EditorGUILayout.PropertyField(openPos, new GUIContent("位移"));
- EditorGUILayout.PropertyField(moveTime, new GUIContent("时间"));
- serializedObject.ApplyModifiedProperties();
- if (GUI.changed)
- {
- }
- }
- }
- }
- }
|