Evo uiUi elements
Selector
A sliding content selector
This page documents Evo UI v1. For the current version, see Evo UI v2. Upgrading? Read the migration guide.
Overview
Selector displays a set of label or icon based items and allows switching between them using previous and next buttons. It is an alternative to a dropdown, and it is recommended to use it only with a small number of items. Navigating a large number of items with this component would not be good UX.
This component is ideal for option pickers, profile selectors, difficulty selection, color or preset cycling, or any situation where users choose among a small list of items.
Properties
Item List
| Name | Type | Description |
|---|---|---|
selectedIndex | int | Index of the currently selected item |
items | List<Item> | List of selectable items |
Item
| Field | Type | Description |
|---|---|---|
label | string | Displayed label |
icon | Sprite | Optional icon |
onItemSelection | UnityEvent | Fired when this item becomes selected |
Settings
| Name | Type | Description |
|---|---|---|
loop | bool | Wraps around when reaching ends |
invokeAtStart | bool | Triggers selection events on Start |
Animation
| Name | Type | Description |
|---|---|---|
isHorizontal | bool | Slides left or right when true |
invertAnimationDirection | bool | Reverses animation direction |
slideOffset | float | Distance used for slide animation |
animationDuration | float | Total time for slide out and in |
animationCurve | AnimationCurve | Curve for easing transitions |
Indicator
| Name | Type | Description |
|---|---|---|
selectedIndicatorAlpha | float | Alpha for active indicator dot |
unselectedIndicatorAlpha | float | Alpha for inactive dots |
indicatorFadeDuration | float | Duration for transitioning indicator alpha |
References
| Name | Type | Description |
|---|---|---|
contentParent | RectTransform | The sliding content area |
contentCanvasGroup | CanvasGroup | Fade control for content |
textObject | TextMeshProUGUI | Displays current item label |
iconObject | Image | Displays current item icon |
indicatorParent | RectTransform | Parent for indicator dots |
indicatorPrefab | GameObject | Prefab for each indicator dot |
prevButton | Button | Button for moving to previous item |
nextButton | Button | Button for moving to next item |
Events
| Name | Type | Description |
|---|---|---|
onSelectionChanged | UnityEvent<int> | Fired when new item is selected |
Public Methods
| Name | Parameters | Description |
|---|---|---|
SetSelection(index, animated) | int, bool | Selects item at index with optional animation |
SetSelection(index) | int | Selects item with animation |
SelectNext() | None | Moves forward |
SelectPrevious() | None | Moves backward |
AddItem(item) | Item | Adds new item |
AddItem(label, icon) | string, Sprite | Adds item with label and optional icon |
RemoveItem(index) | int | Removes item |
ClearItems() | None | Resets all content |
Code Example
using UnityEngine;
using Evo.UI;
public class SelectorExample : MonoBehaviour
{
public Selector selector;
void Start()
{
// Add items
selector.AddItem("Easy");
selector.AddItem("Normal");
selector.AddItem("Hard");
// Listen for changes
selector.onSelectionChanged.AddListener(index =>
{
Debug.Log("Selected: " + selector.items[index].label);
});
// Select specific item
selector.SetSelection(1);
// Move next and previous
selector.SelectNext();
selector.SelectPrevious();
}
}