Skip to main content

Dropdown

YauiDropdown picks one of its options from a list, like uGUI's Dropdown.

When it opens, the dropdown copies its template (an inactive element, usually a scroll view) and shows the copy below the dropdown, on top of everything else in the panel. The template contains one item: a toggle with a text (and optionally an image). The item is copied for each option. Pressing outside the list closes it.

Setup​

Dropdown YauiElement, YauiDropdown
├─ Label YauiText (CaptionText)
└─ Template YauiElement (inactive), YauiScrollView
└─ Content YauiElement
└─ Item YauiElement, YauiToggle
├─ Check YauiElement (the toggle's Graphic)
└─ ItemLabel YauiText (ItemText)
MemberDescription
TemplateThe inactive element copied as the list
CaptionText, CaptionImageShow the text and image of the selected option
ItemText, ItemImageThe text and image of the item in the template. The toggle around ItemText is the item.
OptionsThe options (OptionData: a text and an optional sprite)
ValueThe index of the selected option
OnValueChangedInvoked with the new index when it changes

Scripting​

dropdown.ClearOptions();
dropdown.AddOptions(new[] { "Apple", "Banana", "Cherry" });
dropdown.OnValueChanged.AddListener(index => Debug.Log(dropdown.Options[index].Text));
MemberDescription
AddOptions(...), ClearOptions()Change the options
SetValueWithoutNotify(index)Changes the value without invoking OnValueChanged
RefreshShownValue()Updates the caption after the options were changed directly
Show(), Hide(), IsExpandedOpen and close the list