WindowManager.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. using static Constants;
  6. public class WindowManager : IManager
  7. {
  8. private readonly Dictionary<Window, BaseWindow> Windows = new Dictionary<Window, BaseWindow>();
  9. public BaseWindow this[Window id]
  10. {
  11. get => Windows[id];
  12. set
  13. {
  14. Windows[id] = value;
  15. Windows[id].Activate();
  16. }
  17. }
  18. public WindowManager() => InputManager.Register(MpsKey.ToggleUI, KeyCode.Tab, "Show/hide all UI");
  19. public void DrawWindow(BaseWindow window)
  20. {
  21. if (window.Visible)
  22. {
  23. GUIStyle windowStyle = new GUIStyle(GUI.skin.box);
  24. window.WindowRect = GUI.Window(window.windowID, window.WindowRect, window.GUIFunc, "", windowStyle);
  25. }
  26. }
  27. public void DrawWindows()
  28. {
  29. foreach (BaseWindow window in Windows.Values) DrawWindow(window);
  30. }
  31. public void Update()
  32. {
  33. foreach (BaseWindow window in Windows.Values) window.Update();
  34. }
  35. public void Activate()
  36. {
  37. foreach (BaseWindow window in Windows.Values) window.Activate();
  38. }
  39. public void Deactivate()
  40. {
  41. foreach (BaseWindow window in Windows.Values) window.Deactivate();
  42. }
  43. }
  44. }