public void Play(MusicStackEntry musicStackEntry) { Clear(); musicStack.Add(musicStackEntry); fadeSpeed = 0; fadeVolume = 0; }
// Update is called once per frame void Update() { var entry = musicStackEntryCurrent; var entryPrev = musicStackEntryPrev; var entryDone = ( (audioSourceIntro.clip != null) && (audioSourceLoop.clip == null) && !audioSourceIntro.isPlaying ); if (entryDone) { if (entry.fadeInAfter) { FadeIn(); } musicStack.Remove(entry); audioSourceIntro.Stop(); audioSourceLoop.Stop(); audioSourceIntro.clip = null; audioSourceLoop.clip = null; return; } mixer.SetFloat("Music Pitch", tempo); mixer.SetFloat("Music Pitch Shift", 1F / tempo); mixer.SetFloat("Music Volume", fadeVolume); fadeVolume = Mathf.Max( -40, Mathf.Min( 0, fadeVolume + fadeSpeed ) ); if (entry != null) { mixer.SetFloat("SFX Volume", entry.disableSfx ? -40 : 0); } if (entry == entryPrev) { return; } if (entry == null) { return; } musicStackEntryPrev = entry; entry.Init(); audioSourceIntro.Stop(); audioSourceLoop.Stop(); audioSourceIntro.clip = null; audioSourceLoop.clip = null; audioSourceIntro.outputAudioMixerGroup = mixerGroup; audioSourceLoop.outputAudioMixerGroup = mixerGroup; var dspTime = AudioSettings.dspTime; if (entry.introClip != null) { audioSourceIntro.clip = entry.introClip; audioSourceIntro.PlayScheduled(dspTime + 0.1); } if (entry.loopClip == null) { return; } audioSourceLoop.clip = entry.loopClip; if (entry.introClip != null) { var clipDuration = (double)audioSourceIntro.clip.samples / audioSourceIntro.clip.frequency; audioSourceLoop.PlayScheduled(dspTime + 0.1 + clipDuration); } else { audioSourceLoop.Play(); } }
public void Remove(MusicStackEntry musicStackEntry) { musicStack.Remove(musicStackEntry); }
public void Add(MusicStackEntry musicStackEntry) { musicStack.Add(musicStackEntry); }