Interactive
A unified interactive UI base class with extended states, effects, and events
Overview
Interactive is an extended version of Unity's Selectable that adds rich interaction states, built in ripple and trail effects, audio styling, and fully customizable CanvasGroup based visual transitions. It is the core class behind Evo UI buttons and other selectable components.
The component manages state transitions (Normal, Highlighted, Pressed, Selected, Disabled), handles pointer and submit events, supports audio styling via Styler, and plays animated foreground and background transitions using CanvasGroups.
Usage
Add Interactive component to any UI element that needs advanced visual and audio interaction
Start customizing it to your needs
Transitions
Interactive includes two different state based transition systems you can use.
Canvas Group
You can create objects such as Normal, Highlighted, and/or others, add a CanvasGroup component to them, and assign them under the References tab. After that, you can add your custom UI objects, which will be animated smoothly.
- Disabled: Displays when component state is set to disabled
- Normal: Default appearance
- Highlighted: Shown when pointer is hovered or selected with a controller
- Pressed: Shown when pointer is pressed or controller submit button is pressed
- Selected: Sets the visual state and makes the Interactive object non-interactable until set to other state
Styler Object
Interactive supports state based transitions through the Styler Object system. This includes color changes on hover, click, and other interactions. For more information, see the Styler page.
Properties
Settings
| Name | Type | Description |
|---|---|---|
interactable | bool | Enables or disables Selectable interaction |
transitionDuration | float | Time used when fading between CanvasGroup states |
interactionState | InteractionState | Current state (Normal, Highlighted, Pressed, Selected, Disabled) |
Ripple Effect
| Name | Type | Description |
|---|---|---|
enableRipple | bool | Enables ripple creation on pointer down or submit |
rippleParent | RectTransform | Parent used when instantiating ripple |
ripplePreset | Ripple.Preset | Settings for ripple appearance and timing |
Trail Effect
| Name | Type | Description |
|---|---|---|
enableTrail | bool | Enables pointer trail while hovering |
trailParent | RectTransform | Parent used to spawn the trail |
trailPreset | PointerTrail.Preset | Visual settings for the trail |
Sound Effects
| Name | Type | Description |
|---|---|---|
sfxSource | StylingSource | Determines how audio clips are selected |
stylerPreset | StylerPreset | Audio styling preset used for SFX |
highlightedSFX | AudioMapping | Hover sound |
pressedSFX | AudioMapping | Click sound |
selectedSFX | AudioMapping | Sound played when entering selected state |
References
| Name | Type | Description |
|---|---|---|
disabledCG | CanvasGroup | Displays when component is disabled |
normalCG | CanvasGroup | Default appearance |
highlightedCG | CanvasGroup | Shown when pointer is hovered or selected |
pressedCG | CanvasGroup | Pressed visual state |
selectedCG | CanvasGroup | Permanent selection state |
Events
| Name | Type | Description |
|---|---|---|
onClick | UnityEvent | Fired on pointer click or submit |
onPointerDown | UnityEvent | Fired when pointer is pressed |
onPointerUp | UnityEvent | Fired when pointer is released |
onPointerEnter | UnityEvent | Fired on hover start |
onPointerExit | UnityEvent | Fired on hover exit |
onSelect | UnityEvent | Fired when element is selected |
onDeselect | UnityEvent | Fired when element is deselected |
onSubmit | UnityEvent | Fired when submit is performed (keyboard/controllers) |
External Callback
| Name | Type | Description |
|---|---|---|
OnStateChanged | Action<InteractionState> | Fired when the state changes |
Public Methods
| Name | Parameters | Description |
|---|---|---|
SetState(state, instant) | InteractionState, bool | Sets new interaction state with optional instant transition |
SetInteractable(value) | bool | Toggles interactable and updates visuals |
Code Example
using UnityEngine;
using Evo.UI;
public class InteractiveExample : MonoBehaviour
{
public Interactive interactive;
void Start()
{
// Enable ripple and trail effects
interactive.enableRipple = true;
interactive.enableTrail = true;
// Assign presets
interactive.ripplePreset = new Ripple.Preset
{
shape = someSprite,
color = new Color(1f, 1f, 1f, 0.5f),
duration = 0.4f,
size = 6f,
centered = false
};
interactive.trailPreset = new PointerTrail.Preset
{
shape = someSprite,
color = new Color(1f, 1f, 1f, 0.8f),
scale = 1.1f,
offset = new Vector2(5f, -5f),
fadeDuration = 0.15f
};
// Configure transition
interactive.transitionDuration = 0.15f;
// Register onClick event
interactive.onClick.AddListener(() =>
{
Debug.Log("Interactive element clicked");
});
// Listen for state changes
interactive.OnStateChanged += state =>
{
Debug.Log("New state: " + state);
};
}
}