-
Notifications
You must be signed in to change notification settings - Fork 313
Description
The Problem
Currently, extending Selectable's visual feedback mechanism beyond the built-in Color Tint, Sprite Swap, and Animation transitions is overly burdensome:
-
No Standard Event: There is no Callback when
UnityEngine.UI.Selectable.interactableorUnityEngine.UI.Selectable.SelectionStatechanges. -
Overriding Complexity: Implementing custom transitions requires overriding
Selectable.DoStateTransition(). This forces to create a lot of unnecessary logic (e.g.,MyButton,MyInputFieldetc.) for every inherited component, which is tedious and poor practice. -
Tweening Conflict: Custom Tweening libraries (like DOTween) cannot be adequately integrated with
UnityEngine.UI.Selectable's lifecycle without complex workarounds (e.g., using Animation Event Triggers within Unity Animation System).
Proposed Solution
- Expose SelectionState: Make the
UnityEngine.UI.Selectable.SelectionStatepublic.
- Add Event Transition Type: Introduce a new Enum member to
UnityEngine.UI.Selectable.Transition- Event.
- Implement UnityEvent: Add
UnityEvent<SelectionState>field to theUnityEngine.UI.Selectablecomponent (this event should be invoked within theSelectable.DoStateTransition()method).
Example Usage
With this change, developers could easily hook up any custom logic or Tweening call directly in the Inspector:
-
Inspector: Set Transition to Event.
-
Event Setup: Drag and drop a component into the
OnStateChange<SelectionState>event field. -
Method Call: Select a method that accepts the
SelectionStateas a parameter.