// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik // #if UNITY_EDITOR using UnityEngine; namespace Animancer.Editor { /// [Editor-Only] Utility for implementing IMGUI controls. /// /// Example: /// /// private static readonly int ControlHash = "ControlName".GetHashCode(); /// /// void OnGUI(Rect area) /// { /// var control = new GUIControl(area, ControlHash); /// /// switch (control.EventType) /// { /// case EventType.MouseDown: /// if (control.TryUseMouseDown()) /// { /// } /// break; /// /// case EventType.MouseUp: /// if (control.TryUseMouseUp()) /// { /// } /// break; /// /// case EventType.MouseDrag: /// if (control.TryUseHotControl()) /// { /// } /// break; /// } /// } /// /// https://kybernetik.com.au/animancer/api/Animancer.Editor/GUIControl public readonly struct GUIControl { /************************************************************************************************************************/ /// The position and size of this control public readonly Rect Area; /// The Control ID of this control. public readonly int ID; /// The event being processed by this control. public readonly Event Event; /************************************************************************************************************************/ /// The type of the in relation to this control. public EventType EventType => Event.GetTypeForControl(ID); /// Does the contain the ? public bool ContainsMousePosition => Area.Contains(Event.mousePosition); /************************************************************************************************************************/ /// Creaates a new . public GUIControl(Rect area, Event currentEvent, int idHint, FocusType focusType = FocusType.Passive) { Area = area; Event = currentEvent; ID = GUIUtility.GetControlID(idHint, focusType, area); } /// Creaates a new with the . public GUIControl(Rect area, int idHint, FocusType focusType = FocusType.Passive) : this(area, Event.current, idHint, focusType) { } /************************************************************************************************************************/ /// public bool TryUseMouseDown() => AnimancerGUI.TryUseMouseDown(Area, Event, ID); /// public bool TryUseMouseUp(bool guiChanged = false) => AnimancerGUI.TryUseMouseUp(Event, ID, guiChanged); /// public bool TryUseHotControl(bool guiChanged = true) => AnimancerGUI.TryUseHotControl(Event, ID, guiChanged); /// public bool TryUseKey(KeyCode key = KeyCode.None) => AnimancerGUI.TryUseKey(Event, ID, key); /************************************************************************************************************************/ } } #endif