Logo
UI Elements

Selector

A sliding content selector

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

NameTypeDescription
selectedIndexintIndex of the currently selected item
itemsList<Item>List of selectable items

Item

FieldTypeDescription
labelstringDisplayed label
iconSpriteOptional icon
onItemSelectionUnityEventFired when this item becomes selected

Settings

NameTypeDescription
loopboolWraps around when reaching ends
invokeAtStartboolTriggers selection events on Start

Animation

NameTypeDescription
isHorizontalboolSlides left or right when true
invertAnimationDirectionboolReverses animation direction
slideOffsetfloatDistance used for slide animation
animationDurationfloatTotal time for slide out and in
animationCurveAnimationCurveCurve for easing transitions

Indicator

NameTypeDescription
selectedIndicatorAlphafloatAlpha for active indicator dot
unselectedIndicatorAlphafloatAlpha for inactive dots
indicatorFadeDurationfloatDuration for transitioning indicator alpha

References

NameTypeDescription
contentParentRectTransformThe sliding content area
contentCanvasGroupCanvasGroupFade control for content
textObjectTextMeshProUGUIDisplays current item label
iconObjectImageDisplays current item icon
indicatorParentRectTransformParent for indicator dots
indicatorPrefabGameObjectPrefab for each indicator dot
prevButtonButtonButton for moving to previous item
nextButtonButtonButton for moving to next item

Events

NameTypeDescription
onSelectionChangedUnityEvent<int>Fired when new item is selected

Public Methods

NameParametersDescription
SetSelection(index, animated)int, boolSelects item at index with optional animation
SetSelection(index)intSelects item with animation
SelectNext()NoneMoves forward
SelectPrevious()NoneMoves backward
AddItem(item)ItemAdds new item
AddItem(label, icon)string, SpriteAdds item with label and optional icon
RemoveItem(index)intRemoves item
ClearItems()NoneResets all content

Code Example

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

On this page