SceneWindow.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. internal class SceneWindow : BaseWindow
  5. {
  6. private SceneManager sceneManager;
  7. private SceneManagerTitleBarPane titleBar;
  8. private SceneManagerDirectoryPane directoryList;
  9. private SceneManagerScenePane sceneGrid;
  10. private Rect resizeHandleRect;
  11. private bool resizing;
  12. private float resizeHandleSize = 15f;
  13. private bool visible;
  14. public override bool Visible
  15. {
  16. get => visible;
  17. set
  18. {
  19. visible = value;
  20. if (visible && !sceneManager.Initialized) sceneManager.Initialize();
  21. }
  22. }
  23. public SceneWindow(SceneManager sceneManager)
  24. {
  25. windowRect.width = Screen.width * 0.65f;
  26. windowRect.height = Screen.height * 0.75f;
  27. windowRect.x = Screen.width * 0.5f - windowRect.width * 0.5f;
  28. windowRect.y = Screen.height * 0.5f - windowRect.height * 0.5f;
  29. resizeHandleRect = new Rect(0f, 0f, resizeHandleSize, resizeHandleSize);
  30. this.sceneManager = sceneManager;
  31. SceneModalWindow sceneModalWindow = new SceneModalWindow(this.sceneManager);
  32. this.titleBar = AddPane(new SceneManagerTitleBarPane(sceneManager));
  33. this.titleBar.closeChange += (s, a) => Visible = false;
  34. this.directoryList = AddPane(new SceneManagerDirectoryPane(sceneManager, sceneModalWindow));
  35. this.sceneGrid = AddPane(new SceneManagerScenePane(sceneManager, sceneModalWindow));
  36. this.sceneGrid.SetParent(this);
  37. }
  38. public override void GUIFunc(int id)
  39. {
  40. HandleResize();
  41. Draw();
  42. if (!resizing) GUI.DragWindow();
  43. }
  44. public override void Update()
  45. {
  46. base.Update();
  47. if (InputManager.GetKeyDown(MpsKey.OpenSceneManager)) Visible = !Visible;
  48. }
  49. public override void Deactivate()
  50. {
  51. Visible = false;
  52. }
  53. public override void Draw()
  54. {
  55. GUI.enabled = !SceneManager.Busy && !Modal.Visible;
  56. GUILayout.BeginArea(new Rect(10f, 10f, windowRect.width - 20f, windowRect.height - 20f));
  57. titleBar.Draw();
  58. GUILayout.BeginHorizontal();
  59. directoryList.Draw();
  60. sceneGrid.Draw();
  61. GUILayout.EndHorizontal();
  62. GUILayout.EndArea();
  63. GUI.Box(resizeHandleRect, GUIContent.none);
  64. }
  65. private void HandleResize()
  66. {
  67. resizeHandleRect.x = windowRect.width - resizeHandleSize;
  68. resizeHandleRect.y = windowRect.height - resizeHandleSize;
  69. if (!resizing && Input.GetMouseButton(0) && resizeHandleRect.Contains(Event.current.mousePosition))
  70. {
  71. resizing = true;
  72. }
  73. if (resizing)
  74. {
  75. float rectWidth = Event.current.mousePosition.x;
  76. float rectHeight = Event.current.mousePosition.y;
  77. float minWidth = Utility.GetPix(
  78. SceneManagerDirectoryPane.listWidth
  79. + (int)(SceneManager.sceneDimensions.x * SceneManagerScenePane.thumbnailScale)
  80. );
  81. windowRect.width = Mathf.Max(minWidth, rectWidth);
  82. windowRect.height = Mathf.Max(300, rectHeight);
  83. if (!Input.GetMouseButton(0)) resizing = false;
  84. }
  85. }
  86. }
  87. }