123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEditor.UI;
- using UnityEditor;
- using XRTool.Util;
- using TMPro;
- namespace XRTool.WorldUI
- {
- [InitializeOnLoad]
- [CustomEditor(typeof(XRText))]
- public class XRTextEditor : UnityEditor.UI.TextEditor
- {
- private SerializedProperty textSpacing;
- protected override void OnEnable()
- {
- base.OnEnable();
- textSpacing = serializedObject.FindProperty("textSpacing");
- }
- public override void OnInspectorGUI()
- {
- base.OnInspectorGUI();
- EditorGUILayout.PropertyField(textSpacing, new GUIContent("字间距"));
- serializedObject.ApplyModifiedProperties();
- }
- [MenuItem("GameObject/XRUI/XRText/XRText", priority = 10)]
- static void Init()
- {
- var obj = Instantiate(Resources.Load<XRText>(typeof(XRText).Name));
- obj.name = (typeof(XRText).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);
- obj.transform.localScale = Vector3.one * 0.5f;
- Selection.activeGameObject = obj.gameObject;
- }
- }
- [MenuItem("GameObject/XRUI/XRText/XRTextMesh", priority = 0)]
- static void InitTextMesh()
- {
- var obj = Instantiate(Resources.Load<TextMesh>(typeof(TextMesh).Name));
- obj.name = (typeof(TextMesh).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);
- obj.transform.localScale = Vector3.one * 5;
- Selection.activeGameObject = obj.gameObject;
- }
- }
- //[MenuItem("GameObject/XRUI/XRText/TextMeshPro", priority = 0)]
- //static void InitTextMeshPro()
- //{
- // var obj = Instantiate(Resources.Load<TextMeshPro>(typeof(TextMeshPro).Name));
- // obj.name = (typeof(TextMeshPro).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;
- // }
- //}
- }
- }
|