- Home /
Extending dropdown options to use something like ValueMembers?
Working on a game menu right now I have added a dropdown control from which the player can choose between various presets. The presets themselves are ScriptableObjects which include a string variable storing the preset name. Upon start the dropdown gets populated with the names of all SO's stored in a list.
Now, whenever the player picks an option I can of course read the string value of the selected item, but then I have to walk the whole list and compare the selected item's text to every SO in order to find the one related to the item text.
Is there any way to extend the dropdown options so they can store something akin to WinForms' value members on top of a string and a sprite? The player would still see the name of an item displayed in the dropdown control, while in the background the selected item would still hold a reference to the actual item (i.e. an instance of the ScriptableObject).
If youre using dropdown Ui.
https://docs.unity3d.com/540/Documentation/ScriptReference/UI.Dropdown-value.html
int targetIndex = dropdown.value;
var targetPreset = presets[targetIndex];
@c-Row
I guess that's slightly more elegant, but you would still need to make sure the presets list or array does not get tampered with after populating the dropdown component.