Unity UI 来自文件夹的下拉选项

Unity UI Dropdown options from folder

我有一个下拉菜单,我想读入某个文件夹中的所有文件,然后将它们作为下拉菜单的选项。

if (obj.name.Contains("AudioSphere"))
{
    // Finding the dropdown menu with tag "audioDropdown"
    Dropdown dropdown = GameObject.FindGameObjectWithTag("audioDropdown");

    // Finding all the music files
    FileInfo[] options = getAudioFiles();

    // add Options to the dropdown from list
    for (FileInfo data : options) {
        dropdown.AddOptions(new Dropdown.OptionData(data.Name));

    }
}

我遇到了很多错误,需要一些帮助。我是 Unity 中所有这些 UI 的新手。

private FileInfo[] getAudioFiles()
{
    String path = Application.dataPath + "/Resources/Audiofiles";

    // How to check if exists?

    DirectoryInfo audioFolder = new DirectoryInfo(@path);
   FileInfo[] audioFiles = audioFolder.GetFiles();


    throw new NotImplementedException();
}

这里回答:

LINK to answer