public void InstantiateClip() { if (mode == LoopMode.SingleClip) { GameObject go = new GameObject(AAE_Clip.name); AAEInstance a = go.AddComponent <AAEInstance> (); go.transform.parent = this.transform; a.file = AAE_Clip; //a.clip = file.clip; a.looper = this; nextClip = AAE_Clip; activeClips.Add(go); currentClip = go; } else if (mode == LoopMode.Playlist) { GameObject go = new GameObject(playlist.currentClip.name); AAEInstance a = go.AddComponent <AAEInstance> (); go.transform.parent = this.transform; a.file = playlist.currentClip; a.looper = this; playlist.Advance(); nextClip = playlist.currentClip; activeClips.Add(go); currentClip = go; } }
private IEnumerator FadeClip(GameObject go, FadeType type, float s) { AAEInstance clip = go.GetComponent <AAEInstance> (); clip.independentVolume = true; float i; switch (type) { case FadeType.Out: i = clip.volume; for (float t = 0; t < 1; t += Time.deltaTime / s) { clip.volume = Mathf.Lerp(i, 0, t); yield return(null); } break; case FadeType.In: i = 0; for (float t = 0; t < 1; t += Time.deltaTime / s) { clip.volume = Mathf.Lerp(i, 1, t); yield return(null); } break; } }
void ExitMarkerChange() { currentClip.GetComponent <AAEInstance>().OnExitMarker -= ExitMarkerChange; if (changeMusic != null && changeType != null) { if (changeMusic.GetComponent <AAEClip> () != null) //has AAE Clip { mode = LoopMode.SingleClip; AAE_Clip = changeMusic; } else if (changeMusic.GetComponent <AAEMusicPlaylist> () != null) //has AAE Music Playlist { mode = LoopMode.Playlist; Playlist = changeMusic; } else { Debug.LogError("AAE Music Looper: [void ChangeMusic()]: Invalid GameObject passed! Does not contain 'AAE Clip' or 'AAE Music Playlist' component!"); return; } AAEInstance c = currentClip.GetComponent <AAEInstance> (); switch (changeType) { case ChangeType.None: c.continueLoop = false; c.independentVolume = true; c.volume = 0; Initialise(); InstantiateClip(); break; case ChangeType.Crossfade: c.continueLoop = false; FadeOutClip(currentClip, 3f); Initialise(); InstantiateClip(); FadeInClip(currentClip, 3f); break; // case ChangeType.TransitionClip: // // // break; } } changeCalled = false; }
public void ChangeMusic(GameObject newMusic, ChangeMode changeMode, ChangeType type) { if (!changeCalled) { switch (changeMode) { case ChangeMode.Instant: if (newMusic.GetComponent <AAEClip> () != null) //has AAE Clip { mode = LoopMode.SingleClip; AAE_Clip = newMusic; } else if (newMusic.GetComponent <AAEMusicPlaylist> () != null) //has AAE Music Playlist { mode = LoopMode.Playlist; Playlist = newMusic; } else { Debug.LogError("AAE Music Looper: [void ChangeMusic()]: Invalid GameObject passed! Does not contain 'AAE Clip' or 'AAE Music Playlist' component!"); return; } AAEInstance c = currentClip.GetComponent <AAEInstance> (); c.continueLoop = false; switch (type) { case ChangeType.None: c.independentVolume = true; c.volume = 0; Initialise(); InstantiateClip(); break; case ChangeType.Crossfade: // FadeOutClip(currentClip, 3f); Initialise(); InstantiateClip(); FadeInClip(currentClip, 3f); break; // case ChangeType.TransitionClip: // // // break; } break; case ChangeMode.NextBeat: // changeCalled = true; changeMusic = newMusic; changeType = type; OnBeat += nextBeatChange; break; case ChangeMode.NextBar: // changeCalled = true; changeMusic = newMusic; changeType = type; OnBar += nextBarChange; break; case ChangeMode.ExitMarker: // if (newMusic.GetComponent <AAEMusicPlaylist> () != null) { nextClip = newMusic.GetComponent <AAEMusicPlaylist> ().playlist [0]; currentClip.GetComponent <AAEInstance> ().continueLoop = false; } else if (newMusic.GetComponent <AAEClip> () != null) { nextClip = newMusic; currentClip.GetComponent <AAEInstance> ().continueLoop = false; } changeCalled = true; changeMusic = newMusic; changeType = type; currentClip.GetComponent <AAEInstance> ().OnExitMarker += ExitMarkerChange; break; } } }