EditorMenu.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEngine;
  5. public class EditorMenu
  6. {
  7. private static void InstanciateCanvas(string path)
  8. {
  9. Canvas[] canvases = GameObject.FindObjectsOfType<Canvas>();
  10. if (canvases == null || canvases.Length == 0)
  11. {
  12. EditorUtility.DisplayDialog("No canvas in scene", "Please add a canvas to the scene and try again", "Ok");
  13. return;
  14. }
  15. Canvas canvas = null;
  16. foreach (Canvas c in canvases)
  17. {
  18. if (c.transform.parent == null)
  19. {
  20. canvas = c;
  21. break;
  22. }
  23. }
  24. if (canvas == null)
  25. {
  26. EditorUtility.DisplayDialog("No canvas in scene", "Please add a canvas to the scene and try again", "Ok");
  27. return;
  28. }
  29. GameObject obj = Resources.Load<GameObject>(path);
  30. GameObject newObj = (GameObject)GameObject.Instantiate(obj);
  31. newObj.transform.SetParent(canvas.transform, false);
  32. newObj.name = newObj.name.Replace("(Clone)", "");
  33. Undo.RegisterCreatedObjectUndo(newObj, "Create Object");
  34. }
  35. [MenuItem("Tools/Date Picker/Light Theme")]
  36. public static void AddLightTheme()
  37. {
  38. InstanciateCanvas("MenuPrefabs/MenuLight");
  39. }
  40. [MenuItem("Tools/Date Picker/Dark Theme")]
  41. public static void AddDarkTheme()
  42. {
  43. InstanciateCanvas("MenuPrefabs/MenuDark");
  44. }
  45. }