UI Elements
Selector
Cycle through a compact list of choices
Overview
Selector shows one choice at a time with previous/next buttons and optional indicators. It can generate its indicators in Edit Mode and at runtime.
Usage
Create a Selector prefab and populate Items.
Choose whether navigation wraps with Loop.
Configure the indicator prefab if indicators are wanted.
Bind On Selection Changed to receive the selected index.
Public API
Use Selector in the Evo.UI namespace.
Call Refresh() after editing the item list directly.
Properties
| Name | Type | Description |
|---|---|---|
SelectedIndex | int | Current selected index. |
Fields
| Name | Type | Description |
|---|---|---|
items | List<Item> | Selector.Item choices. |
loop | bool | Wraps between the first and last item. |
Methods
| Name | Parameters | Description |
|---|---|---|
SetSelection() | int index, bool animated, bool invokeEvents = true | Selects an index with animation and event controls. |
SetSelection() | int index | Selects an index with animation and selection events enabled. |
SelectNext() | None | Moves to the next item. |
SelectPrevious() | None | Moves to the previous item. |
AddItem() | Item item | Adds an Item entry. |
AddItem() | string text, Sprite icon = null | Adds an entry from text and an optional icon. |
AddItems() | params Item[] newItems | Adds multiple Item entries. |
AddItems() | params string[] labels | Adds entries from their labels. |
RemoveItem() | int index | Removes an item by index. |
ClearItems() | None | Removes all choices. |
Refresh() | None | Refreshes content and generated indicators. |
Events
| Name | Type | Description |
|---|---|---|
onSelectionChanged | UnityEvent<int> | Invoked with the selected index. |
Example
using UnityEngine;
using Evo.UI;
public class SelectorExample : MonoBehaviour
{
[SerializeField] private Selector target;
private void Start()
{
target.ClearItems();
target.AddItems("Windowed", "Borderless", "Fullscreen");
target.SetSelection(1, animated: false, invokeEvents: false);
target.onSelectionChanged.AddListener(OnModeChanged);
}
// Bind this to a reset button; property assignment updates the selection.
public void ResetMode()
{
target.SelectedIndex = 0;
}
private void OnModeChanged(int index)
{
Debug.Log($"Display mode index: {index}");
}
private void OnDestroy()
{
if (target != null)
target.onSelectionChanged.RemoveListener(OnModeChanged);
}
}