WindowManager.cs 1.5 KB

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