XRSliderEditor.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using UnityEngine;
  2. using UnityEditor.UI;
  3. using UnityEditor;
  4. using XRTool.Util;
  5. namespace XRTool.WorldUI
  6. {
  7. [InitializeOnLoad]
  8. [CustomEditor(typeof(XRSlider))]
  9. public class XRSliderEditor : SliderEditor
  10. {
  11. [MenuItem("GameObject/XRUI/XRSlider", priority = 0)]
  12. static void Init()
  13. {
  14. var obj = Instantiate(Resources.Load<XRSlider>(typeof(XRSlider).Name));
  15. obj.name = (typeof(XRSlider).Name);
  16. if (obj)
  17. {
  18. var parent = Selection.activeGameObject;
  19. if (!parent)
  20. {
  21. var canvas = GameObject.FindObjectsOfType(typeof(Canvas));
  22. if (canvas != null)
  23. {
  24. for (int i = 0; i < canvas.Length; i++)
  25. {
  26. if ((canvas[i] as Canvas).renderMode == RenderMode.WorldSpace)
  27. {
  28. parent = (canvas[i] as Canvas).gameObject;
  29. break;
  30. }
  31. }
  32. }
  33. }
  34. UnityUtil.SetParent(parent ? parent.transform : null, obj.transform);
  35. Selection.activeGameObject = obj.gameObject;
  36. }
  37. }
  38. }
  39. }