No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BoolFieldOverlayPopupWindow.cs 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using UnityEditor.Overlays;
  2. using UnityEngine;
  3. using UnityEngine.UIElements;
  4. namespace UnityEditor.Tilemaps
  5. {
  6. internal abstract class BoolFieldOverlayPopupWindow : OverlayPopupWindow
  7. {
  8. private BaseField<bool> trigger;
  9. private bool isLocked;
  10. private Rect screenRect;
  11. private Vector2 size;
  12. protected virtual void OnDisable()
  13. {
  14. // Disable trigger state if closed outside of trigger
  15. if (trigger != null && (trigger.pseudoStates & PseudoStates.Hover) == 0)
  16. trigger.SetValueWithoutNotify(false);
  17. }
  18. protected void ToggleMode<T>(bool value) where T : BoolFieldOverlayPopupWindow
  19. {
  20. isLocked = value;
  21. ShowOverlayPopup<T>(trigger, screenRect, size, isLocked);;
  22. }
  23. private void InitDropDown()
  24. {
  25. var mode = ShowMode.PopupMenu;
  26. var giveFocus = true;
  27. this.position = this.ShowAsDropDownFitToScreen(screenRect, size, null);
  28. if (ContainerWindow.IsPopup(mode))
  29. this.ShowPopupWithMode(mode, giveFocus);
  30. else
  31. this.ShowWithMode(mode);
  32. this.position = this.ShowAsDropDownFitToScreen(screenRect, size, null);
  33. double width1 = (double)this.position.width;
  34. Rect position = this.position;
  35. double height1 = (double)position.height;
  36. this.minSize = new Vector2((float)width1, (float)height1);
  37. position = this.position;
  38. double width2 = (double)position.width;
  39. position = this.position;
  40. double height2 = (double)position.height;
  41. this.maxSize = new Vector2((float)width2, (float)height2);
  42. if (giveFocus && (UnityEngine.Object)EditorWindow.focusedWindow != (UnityEngine.Object) this)
  43. this.Focus();
  44. else
  45. this.Repaint();
  46. if (!isLocked)
  47. this.m_Parent.AddToAuxWindowList();
  48. this.m_Parent.window.m_DontSaveToLayout = true;
  49. }
  50. public static void ShowOverlayPopup<T>(BaseField<bool> trigger, Rect position, Vector2 size, bool isLocked) where T : BoolFieldOverlayPopupWindow
  51. {
  52. CloseAllWindows<T>();
  53. var instance = ScriptableObject.CreateInstance<T>();
  54. instance.trigger = trigger;
  55. instance.size = size;
  56. instance.screenRect = position;
  57. instance.isLocked = isLocked;
  58. instance.InitDropDown();
  59. }
  60. public static void ShowOverlayPopup<T>(BaseField<bool> trigger, Vector2 size, bool isLocked) where T : BoolFieldOverlayPopupWindow
  61. {
  62. var rect = GUIUtility.GUIToScreenRect(trigger.worldBound);
  63. ShowOverlayPopup<T>(trigger, rect, size, isLocked);
  64. }
  65. public static void CloseAllWindows<T>() where T : BoolFieldOverlayPopupWindow
  66. {
  67. foreach (T obj in Resources.FindObjectsOfTypeAll<T>())
  68. obj.Close();
  69. }
  70. }
  71. }