How to add more UI elements to Dropdown OptionData except default string and sprite values in Unity?

Viewed 265

I have a json file which has some information about countries. And I have a dropdown in my scene. In that dropdown I show country flags and country names. I retrieve country names and flag paths from that json file. My json file:

enter image description here

My countydata script:

enter image description here

And my current view like that:

enter image description here

So far so good. However I want to show one more “string (or int)” field in there but dropdowns metadata cannot be modified and it only allows me to add (string text, Sprite image).

Dropdown metadata:

enter image description here

In my current situation those are countrynames, flagpaths. I think I should be able to do something like OptionData(string text, Sprite image, string/int) so I can retrieve “coinPlaces” values from my json (which is “1” here) and show it in Dropdown. This is how I want it to look:

enter image description here

In scene I can add anything I want to Dropdowns template like this:

enter image description here

However, even though I can get the "coinPlaces" values from the json, I can't show it in the dropdown because I can't change the metadata.

1 Answers

You are using constructor in C# to initialize default value when you create new instance of this class. So it's impossible to add a coin value to the operator.

I think the best way here is to make another class inherit from this metadata class

Related