Programmatically change dropdown menu options in Unity3D

I got Unity3D 5.2 and first used the Dropdown GUI element. It is easy to use in insepctor, but I want the parameters to be displayed, depending on my files in the "Resources / Forms" /

So, in the drop-down list, all the file names that I got in Resources / Shapes / should be displayed, but I can not get this property in the attached C # script. After reading the manual, the drop-down list should have a property named "Parameters" and it should have a string and an image variable. (So, for my understanding, its two-dimensional array-ish-type)

Unfortunately, I cannot use the following script (pseudo-code, since it does not work)

GameObject obj = GameObject.Find("Dropdown");

var info = new DirectoryInfo("Assets/Resources/Shapes");
var fileInfo = info.GetFiles();
foreach (var file in fileInfo)
{
    //Add OptionsString Pseudo-Code
    obj.Options += file; // Options doesnt exist
}

- , Options Dropdown pls, - Google. , Unity

+4
2
List<string> list = new List<string> { "option1", "option2" };
var dropdown = GetComponent<Dropdown>();
dropdown.options.Clear();
foreach (string option in list)
{
    dropdown.options.Add(new Dropdown.OptionData(option));
}
+5

:

Dropdown.OptionData list = new Dropdown.OptionData("Name");
obj.GetComponent<Dropdown>().options.Add(list);
+3

Source: https://habr.com/ru/post/1613197/


All Articles