2016-04-22 58 views
0

我有一個下拉列表,我想讀取某個文件夾中的所有文件,然後將它們作爲下拉選項。 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(); 
} 

回答