TransitionLibraryWindowHighlighter.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. #if UNITY_EDITOR
  3. using Animancer.TransitionLibraries;
  4. using UnityEditor;
  5. using UnityEngine;
  6. namespace Animancer.Editor.TransitionLibraries
  7. {
  8. /// <summary>[Editor-Only]
  9. /// An <see cref="EditorWindow"/> for configuring <see cref="TransitionLibraryAsset"/>.
  10. /// </summary>
  11. /// https://kybernetik.com.au/animancer/api/Animancer.Editor.TransitionLibraries/TransitionLibraryWindowHighlighter
  12. public class TransitionLibraryWindowHighlighter
  13. {
  14. /************************************************************************************************************************/
  15. private static readonly Color
  16. SelectionHighlightColor = new(0.5f, 0.5f, 1, 0.1f),
  17. HoverHighlightColor = new(0.5f, 1, 0.5f, 0.1f);
  18. /************************************************************************************************************************/
  19. /// <summary>The current <see cref="Event.type"/>.</summary>
  20. public EventType EventType { get; private set; }
  21. /// <summary>The the mouse currently over the highlighter area.</summary>
  22. public bool IsMouseOver { get; private set; }
  23. /// <summary>The the hover highlight currently visible.</summary>
  24. public bool DidHoverHighlight { get; private set; }
  25. /************************************************************************************************************************/
  26. /// <summary>Gathers the details of the <see cref="Event.current"/>.</summary>
  27. public void BeginGUI(Rect area)
  28. {
  29. var currentEvent = Event.current;
  30. EventType = currentEvent.type;
  31. IsMouseOver = area.Contains(currentEvent.mousePosition);
  32. DidHoverHighlight = false;
  33. }
  34. /************************************************************************************************************************/
  35. /// <summary>Repaints the `window` if necessary.</summary>
  36. public void EndGUI(TransitionLibraryWindow window)
  37. {
  38. if (DidHoverHighlight && window != EditorWindow.mouseOverWindow)
  39. {
  40. DidHoverHighlight = false;
  41. window.Repaint();
  42. }
  43. else if (EventType == EventType.MouseMove)
  44. {
  45. window.Repaint();
  46. }
  47. }
  48. /************************************************************************************************************************/
  49. /// <summary>Draws highlights for the `area`.</summary>
  50. public void DrawHighlightGUI(Rect area, bool selected, bool hover)
  51. {
  52. if (selected)
  53. {
  54. EditorGUI.DrawRect(area, SelectionHighlightColor);
  55. }
  56. if (hover)
  57. {
  58. DidHoverHighlight = true;
  59. EditorGUI.DrawRect(area, HoverHighlightColor);
  60. }
  61. }
  62. /************************************************************************************************************************/
  63. }
  64. }
  65. #endif