OptionSelector
An OptionSelector is a "‹ value ›" cycler for a short list of choices, such as a resolution, a quality level or a difficulty. Its value is the index of the shown choice. The arrow buttons step back and forward, a click on the text steps forward, and Left and Right on the keyboard or a gamepad step through the choices. A row of dots shows the position, and the text slides in the direction of a step.


Video tutorial: Option selector. All videos: Video tutorials.
<UIToolbox.OptionSelector
label="Difficulty"
choices="Easy,Normal,Hard,Nightmare"
value="1" />
<UIToolbox.OptionSelector
label="Resolution"
choices="1280 x 720,1920 x 1080,2560 x 1440"
wrap="false"
show-dots="false" />
var quality = new OptionSelector("Quality")
{
Choices = new List<string> { "Low", "Medium", "High" }
};
quality.RegisterValueChangedCallback(evt =>
Debug.Log($"{quality.Text} (index {evt.newValue})"));
quality.Next();
// An enum gives the choices; the names are nicified, or the
// [InspectorName] of a value
var level = new OptionSelector("Level");
level.SetEnum(Difficulty.Normal);
level.RegisterValueChangedCallback(_ =>
game.Difficulty = level.GetEnum<Difficulty>());
// Choices with a disabled one: the arrows and the keys skip it
quality.Items = new List<ChoiceItem>
{
"1280 x 720",
"1920 x 1080",
new("3840 x 2160", enabled: false)
};
Settings
| Member | Description |
|---|---|
Choices (choices) |
The choices as text. Comma separated in UXML. A get gives a copy of the texts. |
Items |
The choices as ChoiceItems. A choice with Enabled off is skipped by the arrows and the keys. The selector uses the text and the enabled state. Set the list again after you change it. |
Wrap (wrap) |
A step past the last choice goes to the first, and the reverse (true). Off stops at the ends. |
ShowDots (show-dots) |
Shows a row of dots with the position (true). A list of more than 12 choices shows no dots. |
Animate (animate) |
Slides the text in the direction of a change (true). Off, and in the UI Builder, the text changes at once. The workspace setting for animations applies too. |
AnimationDuration (animation-duration) |
The time of the slide of the text, in milliseconds. Default 160. 0 changes the text at once. |
AnimationEasing (animation-easing) |
The curve of the slide of the text, one of the easing curves. Default OutCubic. With OutBack or OutElastic, the text that comes in goes past the middle and comes back. |
value |
The index of the shown choice. A set keeps it between 0 and the last choice. |
SelectedItem, Text |
The shown ChoiceItem (null without choices) and its text. |
The UXML value attribute is the index, applied after the choices. A new list of choices keeps the value in range.
Methods
| Method | Description |
|---|---|
Next(), Previous() |
Show the next or the previous enabled choice. They do nothing at the end without Wrap. |
SetEnum<T>(value) |
Shows the values of the enum T as the choices and selects value. A value that shares its number with an earlier one has no choice of its own. A flags enum is not a fit. |
SetEnumWithoutNotify<T>(value) |
Like SetEnum, without a change event. |
GetEnum<T>() |
The value of the enum that is shown. |
SetValueWithoutNotify(index) |
Shows an index without a change event. |
Events
A change of the value from a click, a key, Next, Previous or value sends one ChangeEvent<int> with the new index. A step that cannot move, such as Next at the end without Wrap, sends none, and SetValueWithoutNotify sends none. Read the text with Text or GetEnum<T>() in the callback.
Mouse and keyboard
| Input | Action |
|---|---|
| Click on an arrow | Steps back or forward. An arrow is disabled when there is no step in its direction. |
| Click on the text | Steps forward, and focuses the selector. |
| Left, Right (arrow keys, gamepad D-pad and stick) | Step back and forward. At the end without Wrap the selector does not use the key, so the focus moves on. |
| Enter, Space, gamepad confirm | Steps forward. |
PropertyGrid and settings panels
A PropertyGrid row for an enum, or for a string or an int with [Choices], shows an OptionSelector when the member has the [Selector] attribute, or when UseSelectors of the grid is on. A flags enum keeps its toggles. The GraphicsSettingsPanel of the Game menu example sets UseSelectors, so its resolution, quality and enum rows cycle. See PropertyGrid.
public class Options
{
[Selector] public Difficulty Level;
[Selector, Choices(nameof(Resolutions))] public string Resolution =
"1920 x 1080";
}
Performance
- A step,
Next,Previousand a set of the same value allocate nothing. - A slide uses one scheduled item that pauses when the slide ends. It changes the translate and the opacity of two labels and never the layout.
- A change of the choices rebuilds the dots, so set
Choicesonce, not for each frame. APropertyGridrow sets them again only when the texts differ.
In the examples

Styling
| Class | Element |
|---|---|
tb-option-selector |
The field. |
tb-option-selector__arrow |
An arrow button. tb-option-selector__arrow--previous and tb-option-selector__arrow--next mark the two. |
tb-option-selector__center |
The column of the text and the dots. |
tb-option-selector__viewport |
The clipped area of the text. A click on it steps forward. |
tb-option-selector__text |
A text label. Two labels take turns during a slide. |
tb-option-selector__dots |
The row of dots. |
tb-option-selector__dot |
A dot. tb-option-selector__dot--selected marks the shown choice. |
The colors come from --tb-color-accent, --tb-color-text, --tb-color-border and --tb-color-surface-alt. The width comes from the min-width of the input (160 px); change it in your style sheet for longer texts.
The OptionSelectorDemo scene shows the difficulty of a new game with its choices in the UXML, the text size of the subtitles from an enum, and a resolution with a choice that the monitor cannot show. The Game menu example uses selectors for the theme, the text size and the graphics rows.