using UnityEngine; using UnityEditor.UI; using UnityEditor; using XRTool.Util; namespace XRTool.WorldUI { [InitializeOnLoad] [CustomEditor(typeof(XRSlider))] public class XRSliderEditor : SliderEditor { [MenuItem("GameObject/XRUI/XRSlider", priority = 0)] static void Init() { var obj = Instantiate(Resources.Load(typeof(XRSlider).Name)); obj.name = (typeof(XRSlider).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; } } } }