Logo
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.

Preview

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

NameTypeDescription
SelectedIndexintCurrent selected index.

Fields

NameTypeDescription
itemsList<Item>Selector.Item choices.
loopboolWraps between the first and last item.

Methods

NameParametersDescription
SetSelection()int index, bool animated, bool invokeEvents = trueSelects an index with animation and event controls.
SetSelection()int indexSelects an index with animation and selection events enabled.
SelectNext()NoneMoves to the next item.
SelectPrevious()NoneMoves to the previous item.
AddItem()Item itemAdds an Item entry.
AddItem()string text, Sprite icon = nullAdds an entry from text and an optional icon.
AddItems()params Item[] newItemsAdds multiple Item entries.
AddItems()params string[] labelsAdds entries from their labels.
RemoveItem()int indexRemoves an item by index.
ClearItems()NoneRemoves all choices.
Refresh()NoneRefreshes content and generated indicators.

Events

NameTypeDescription
onSelectionChangedUnityEvent<int>Invoked with the selected index.

Example

SelectorExample.cs
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);
    }
}

On this page