UMPSettingsWindow.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace UMP.Editor
  4. {
  5. public class UMPSettingsWindow : EditorWindow
  6. {
  7. private static bool _isCreated = false;
  8. private static bool _isInitialized = false;
  9. [MenuItem("Window/UMP Settings")]
  10. public static void Init()
  11. {
  12. // Close opened window
  13. if (_isInitialized || _isCreated)
  14. {
  15. var settingsWindow = GetWindow(typeof(UMPSettingsWindow));
  16. settingsWindow.Close();
  17. return;
  18. }
  19. _isCreated = true;
  20. {
  21. // Get existing window
  22. var settingsWindow = CreateInstance<UMPSettingsWindow>();
  23. if (settingsWindow != null)
  24. settingsWindow.SetupWindow();
  25. }
  26. }
  27. public void SetupWindow()
  28. {
  29. var width = 256f;
  30. var height = 512f;
  31. _isCreated = true;
  32. position = new Rect((Screen.width * 0.5f) - (width * 0.5f), (Screen.height * 0.5f) - (height * 0.5f), width, height);
  33. minSize = new Vector2(256f, 512f);
  34. titleContent = new GUIContent("UMP Settings");
  35. _isInitialized = true;
  36. ShowUtility();
  37. Repaint();
  38. }
  39. void OnEnable()
  40. {
  41. if (!_isCreated)
  42. SetupWindow();
  43. }
  44. void OnDisable()
  45. {
  46. _isInitialized = false;
  47. _isCreated = false;
  48. Repaint();
  49. }
  50. void OnGUI()
  51. {
  52. if (!_isInitialized)
  53. {
  54. EditorGUILayout.LabelField("Initialising Settings Window...");
  55. return;
  56. }
  57. var settingsEditor = UnityEditor.Editor.CreateEditor(UMPSettings.Instance);
  58. settingsEditor.OnInspectorGUI();
  59. }
  60. }
  61. }