BaseWindow.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. public abstract class BaseWindow : BaseWindowPane
  5. {
  6. private static int id = 765;
  7. private static int ID => id++;
  8. public readonly int windowID = ID;
  9. protected Rect windowRect = new Rect(0f, 0f, 480f, 270f);
  10. public virtual Rect WindowRect
  11. {
  12. get => windowRect;
  13. set
  14. {
  15. value.x = Mathf.Clamp(
  16. value.x, -value.width + Utility.GetPix(20), Screen.width - Utility.GetPix(20)
  17. );
  18. value.y = Mathf.Clamp(
  19. value.y, -value.height + Utility.GetPix(20), Screen.height - Utility.GetPix(20)
  20. );
  21. windowRect = value;
  22. }
  23. }
  24. protected Vector2 MiddlePosition => new Vector2(
  25. (Screen.width / 2) - (windowRect.width / 2), (Screen.height / 2) - (windowRect.height / 2)
  26. );
  27. public virtual void HandleZoom()
  28. {
  29. if (Input.mouseScrollDelta.y != 0f && Visible)
  30. {
  31. Vector2 mousePos = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
  32. if (WindowRect.Contains(mousePos)) Input.ResetInputAxes();
  33. }
  34. }
  35. public virtual void Update() => HandleZoom();
  36. public virtual void Activate() { }
  37. public virtual void Deactivate() { }
  38. public virtual void GUIFunc(int id)
  39. {
  40. Draw();
  41. GUI.DragWindow();
  42. }
  43. }
  44. }