文件夹中的 Unity UI 下拉列表选项



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

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();
}

答案如下:

链接回答

最新更新