123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEditor.UI;
- using UnityEditor;
- using XRTool.Util;
- namespace XRTool.WorldUI
- {
- [InitializeOnLoad]
- [CustomEditor(typeof(XRButton))]
- public class XRButtonEditor : ButtonEditor
- {
- private SerializedProperty thickness;
- private SerializedProperty pressDis;
- private SerializedProperty isShowBack;
- private SerializedProperty isShowBox;
- private SerializedProperty pressTime;
- private SerializedProperty isTweenOnClick;
- private Vector2 size;
- private XRButton button;
- [MenuItem("GameObject/XRUI/XRButton", priority = 0)]
- static void Init()
- {
- var obj = Instantiate(Resources.Load<XRButton>(typeof(XRButton).Name));
- obj.name = (typeof(XRButton).Name);
- 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();
- thickness = serializedObject.FindProperty("thickness");
- pressDis = serializedObject.FindProperty("pressDis");
- isShowBack = serializedObject.FindProperty("isShowBack");
- isShowBox = serializedObject.FindProperty("isShowBox");
- pressTime = serializedObject.FindProperty("pressTime");
- isTweenOnClick = serializedObject.FindProperty("isTweenOnClick");
- button = target as XRButton;
- if (button)
- {
- size = button.Body.rect.size;
- }
- }
- public override void OnInspectorGUI()
- {
- base.OnInspectorGUI();
- EditorGUILayout.PropertyField(thickness, new GUIContent("按钮厚度"));
- EditorGUILayout.PropertyField(pressDis, new GUIContent("压缩比例"));
- EditorGUILayout.PropertyField(pressTime, new GUIContent("压缩时间比例"));
- EditorGUILayout.PropertyField(isShowBack, new GUIContent("显示背景"));
- EditorGUILayout.PropertyField(isShowBox, new GUIContent("显示Box"));
- EditorGUILayout.PropertyField(isTweenOnClick, new GUIContent("是否移动"));
- if (button.Body.rect.size != size)
- {
- size = button.Body.rect.size;
- button.AutoSetSize();
- //AutoSetScale(button.transform,size);
- }
- serializedObject.ApplyModifiedProperties();
- if (GUI.changed)
- {
- button.Back.gameObject.SetActive(button.isShowBack);
- button.Box.gameObject.SetActive(button.isShowBox);
- button.UpdateThickness();
- }
- }
- }
- }
|