BaseWindow.cs 1.7 KB

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