示例#1
0
        public void PlayTrack(Tracks track)
        {
            Music newTrack = null;

            Console.WriteLine(track);

            switch (track) {
                case Tracks.GAME:
                    newTrack = gameMusic;
                    break;
                case Tracks.BOSS:
                    newTrack = bossMusic;
                    break;
            }

            if ((newTrack == currentTrack) || (newTrack == null)) {
                return;
            }

            if (currentTrack == null) {
                newTrack.Volume = 1;
                newTrack.Play();
            } else {
                if (currentCoroutine > -1) {
                    Game.Instance.Coroutine.Stop(currentCoroutine);
                }
                currentCoroutine = Game.Instance.Coroutine.Start(FadeTracks(currentTrack, newTrack));
            }

            currentTrack = newTrack;
        }
示例#2
0
        private IEnumerator FadeTracks(Music oldTrack, Music newTrack)
        {
            while (oldTrack.Volume > 0.7f) {
                oldTrack.Volume = Util.Lerp(oldTrack.Volume, 0.0f, 0.03f);
                newTrack.Volume = 1.0f - oldTrack.Volume;
                yield return 0;
            }

            newTrack.Play();

            while (oldTrack.Volume > 0.01f) {
                oldTrack.Volume = Util.Lerp(oldTrack.Volume, 0.0f, 0.03f);
                newTrack.Volume = 1.0f - oldTrack.Volume;
                yield return 0;
            }

            oldTrack.Stop();
            oldTrack.Volume = 0.0f;
            newTrack.Volume = 1.0f;
        }