/// <summary> /// Searchs for a Song in all the catalogs currently in memory /// </summary> private AudioCatalog.IndexedClip findSongInCatalogs(string Id) { AudioCatalog.IndexedClip retVal = null; for (int i = 0; i < this.audioCatalogs.Length; i++) { AudioCatalog.IndexedClip c = this.audioCatalogs[i].GetSong(Id); if (c != null) { retVal = c; break; } } return(retVal); }
/// <summary> /// Play a Song /// </summary> /// <param name="Id">The Id of the Song you want to be played</param> /// <param name="loop">Play in loop mode</param> /// <param name="inmediate">Don't fade out if true</param> private void playSong(string Id, bool loop, bool inmediate = false) { bool played = false; AudioCatalog.IndexedClip song = this.findSongInCatalogs(Id); if (song != null) { if (song.Clip != null) { //make sure we have a audiosource to play the song with this.refreshSongSource(); //play the song this.songSource.volume = inmediate ? GameManager.Instance.Options.Options.MusicVolume : 0.0f; this.songSource.clip = song.Clip; this.songSource.loop = loop; this.songSource.Play(); //fade out the previous song if (!inmediate) { this.fadeTime = FadeInDuration; this.fadeTimeLeft = FadeInDuration; this.fadingIn = true; } else { this.fadingIn = false; } //anotate the current song this.currentSongName = song.Id; this.currentSongRepeat = loop; played = true; pauseMusic = false; stopMusic = false; } } if (!played) { if ((Id != null) && (Id != string.Empty)) { Debug.LogError(string.Format("Song {0} not found in AudioCatalogs!", Id)); } } }