Skip to content

Instantly share code, notes, and snippets.

@prophetgoddess
Created January 25, 2017 04:51
Show Gist options
  • Save prophetgoddess/9b5f76df72cd1c02949145e128449c76 to your computer and use it in GitHub Desktop.
Save prophetgoddess/9b5f76df72cd1c02949145e128449c76 to your computer and use it in GitHub Desktop.
song loader from AUDIOCHROMA
IEnumerator GetSongs() {
songs = new List<AudioClip>();
string path = Application.dataPath;
path = Directory.GetParent(path).ToString();
path = path += "/Songs";
if (Directory.Exists(path)) {
string[] songFilePaths = Directory.GetFiles(path);
foreach (string filePath in songFilePaths) {
string fileName = Path.GetFileNameWithoutExtension(filePath);
string fileExtension = Path.GetExtension(filePath);
if (fileExtension == ".ogg") {
WWW download = new WWW("file://" + filePath);
yield return download;
AudioClip ac = download.GetAudioClip(false);
ac.name = fileName;
songs.Add(ac);
dropdown.options.Add(new Dropdown.OptionData(fileName));
}
}
if (songs.Count > 0) {
fade.raycastTarget = false;
dropdown.value = 0;
dropdown.RefreshShownValue();
SongPreview();
StartCoroutine(FadeBack());
loadingScreenText.gameObject.SetActive(false);
}
else {
loadingScreenText.text = "No songs found. Please make sure the songs are in .ogg format, and that they are in the Songs folder in the same directory as AUDIOCHROMA.";
}
}
else {
loadingScreenText.text = "The Songs folder appears to be missing. Please create a Songs folder in the same directory as AUDIOCHROMA and fill it with music.";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment