123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using SC.XR.Unity;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEditor;
- using UnityEditor.UI;
- using UnityEngine;
- using UnityEngine.UI;
- using XRTool.Util;
- namespace XRTool.UI
- {
- [InitializeOnLoad]
- [CustomEditor(typeof(XRInputField))]
- public class XRInputFieldEditor : InputFieldEditor
- {
- [MenuItem("GameObject/XRUI/SCInputField", priority = 6)]
- static void Init()
- {
- var obj = Instantiate(Resources.Load<SCInputField>(typeof(SCInputField).Name));
- obj.name = (typeof(SCInputField).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;
- if (!obj.textComponent)
- {
- obj.textComponent = UnityUtil.GetBreadthChild<Text>(obj.transform, "Text");
- }
- if (!obj.placeholder)
- {
- obj.placeholder = UnityUtil.GetBreadthChild<Graphic>(obj.transform, "Placeholder");
- }
- }
- }
- [MenuItem("GameObject/XRUI/XRInputField", priority = 6)]
- static void InitXRInputField()
- {
- var obj = Instantiate(Resources.Load<XRInputField>(typeof(XRInputField).Name));
- obj.name = (typeof(XRInputField).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;
- if (!obj.textComponent)
- {
- obj.textComponent = UnityUtil.GetBreadthChild<Text>(obj.transform, "Text");
- }
- if (!obj.placeholder)
- {
- obj.placeholder = UnityUtil.GetBreadthChild<Graphic>(obj.transform, "Placeholder");
- }
- }
- }
- }
- }
|