1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEditor;
- using UnityEditor.UI;
- using UnityEngine;
- using XRTool.Util;
- namespace XRTool.WorldUI
- {
- [InitializeOnLoad]
- [CustomEditor(typeof(XRIcon))]
- public class XRIconEditor : ImageEditor
- {
- private XRIcon xrIcon;
- private SerializedProperty icon;
- [MenuItem("GameObject/XRUI/XRIcon", priority = 10)]
- static void Init()
- {
- var obj = Instantiate(Resources.Load<XRIcon>(typeof(XRIcon).Name));
- obj.name = (typeof(XRIcon).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();
- icon = serializedObject.FindProperty("icon");
- xrIcon = target as XRIcon;
- xrIcon.AutoSetSprite();
- }
- /// <summary>
- ///
- /// </summary>
- public override void OnInspectorGUI()
- {
- base.OnInspectorGUI();
- EditorGUILayout.PropertyField(icon, new GUIContent("图标"));
- serializedObject.ApplyModifiedProperties();
- if (GUI.changed)
- {
- if (xrIcon)
- {
- xrIcon.AutoSetSprite();
- }
- }
- }
- }
- }
|