123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- using UnityEngine;
- namespace COM3D2.MeidoPhotoStudio.Plugin
- {
- public class SceneWindow : BaseWindow
- {
- private const float resizeHandleSize = 15f;
- private readonly SceneManager sceneManager;
- private readonly SceneManagerTitleBarPane titleBar;
- private readonly SceneManagerDirectoryPane directoryList;
- private readonly SceneManagerScenePane sceneGrid;
- private Rect resizeHandleRect;
- private bool resizing;
- private bool visible;
- public override bool Visible
- {
- get => visible;
- set
- {
- visible = value;
- if (visible && !sceneManager.Initialized) sceneManager.Initialize();
- }
- }
- public SceneWindow(SceneManager sceneManager)
- {
- windowRect.width = Screen.width * 0.65f;
- windowRect.height = Screen.height * 0.75f;
- windowRect.x = (Screen.width * 0.5f) - (windowRect.width * 0.5f);
- windowRect.y = (Screen.height * 0.5f) - (windowRect.height * 0.5f);
- resizeHandleRect = new Rect(0f, 0f, resizeHandleSize, resizeHandleSize);
- this.sceneManager = sceneManager;
- SceneModalWindow sceneModalWindow = new SceneModalWindow(this.sceneManager);
- titleBar = AddPane(new SceneManagerTitleBarPane(sceneManager));
- titleBar.CloseChange += (s, a) => Visible = false;
- directoryList = AddPane(new SceneManagerDirectoryPane(sceneManager, sceneModalWindow));
- sceneGrid = AddPane(new SceneManagerScenePane(sceneManager, sceneModalWindow));
- sceneGrid.SetParent(this);
- }
- public override void GUIFunc(int id)
- {
- HandleResize();
- Draw();
- if (!resizing) GUI.DragWindow();
- }
- public override void Update()
- {
- base.Update();
- if (InputManager.GetKeyDown(MpsKey.OpenSceneManager)) Visible = !Visible;
- }
- public override void Deactivate()
- {
- Visible = false;
- }
- public override void Draw()
- {
- GUI.enabled = !SceneManager.Busy && !Modal.Visible;
- GUILayout.BeginArea(new Rect(10f, 10f, windowRect.width - 20f, windowRect.height - 20f));
- titleBar.Draw();
- GUILayout.BeginHorizontal();
- directoryList.Draw();
- sceneGrid.Draw();
- GUILayout.EndHorizontal();
- GUILayout.EndArea();
- GUI.Box(resizeHandleRect, GUIContent.none);
- }
- private void HandleResize()
- {
- resizeHandleRect.x = windowRect.width - resizeHandleSize;
- resizeHandleRect.y = windowRect.height - resizeHandleSize;
- if (!resizing && Input.GetMouseButton(0) && resizeHandleRect.Contains(Event.current.mousePosition))
- {
- resizing = true;
- }
- if (resizing)
- {
- float rectWidth = Event.current.mousePosition.x;
- float rectHeight = Event.current.mousePosition.y;
- float minWidth = Utility.GetPix(
- SceneManagerDirectoryPane.listWidth
- + (int)(SceneManager.sceneDimensions.x * SceneManagerScenePane.thumbnailScale)
- );
- windowRect.width = Mathf.Max(minWidth, rectWidth);
- windowRect.height = Mathf.Max(300, rectHeight);
- if (!Input.GetMouseButton(0)) resizing = false;
- }
- }
- }
- }
|