Friday, August 1, 2025

unity – UI Dropdown – Is it attainable to have a customized worth sort as a substitute of an index?

I am utilizing the UI Dropdown part which helps you to set the textual content of an choice (OptionData) solely. The worth of an choice is the index place within the choices checklist, so there is no such thing as a solution to set this.

My downside is that I’ve a dictionary that I take advantage of to populate the dropdown choices, however I would really like the worth of the choice to be the id of the tile class, not the index place.


Edit:

I do know I can entry parts from the checklist by utilizing the worth (index).

checklist(dropdown.worth).id

However I needed to see about extending the dropdown with this small change, as I’ve another adjustments I want to make, however needed to start out with one thing easy first simply to get an concept of what’s possile.

I don’t want somebody to put up a full code resolution. Am largely after some pointers. Trying on the dropdown class, I do not see how I can prolong it to switch some issues (worth on this case), it seems like I must implement by personal model?


Some code will make this slightly clearer I feel:

// All tiles into checklist.
Checklist checklist = new Checklist(mydictionary.Values);

// Kind all tiles based mostly on the tile identify.
checklist.Kind((x,y) => x.identify.CompareTo(y.identify));

// Present method so as to add checklist to dropdown.
for(int i=0; i

Or if the worth is required internally for some purpose, then possibly an additional property that may be set and retrieved.

for(int i=0; i

I took a have a look at the DropDown class to see if I may prolong it and add the “tile_id” choice in, however I acquired fully misplaced on what to do, as I’m nonetheless fairly new to C#.

https://bitbucket.org/Unity-Applied sciences/ui/src/a3f89d5f7d145e4b6fa11cf9f2de768fea2c500f/UnityEngine.UI/UI/Core/Dropdown.cs

https://docs.unity3d.com/ScriptReference/UI.Dropdown.html

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles