private void OnSceneLoaded(Scene scene, LoadSceneMode mode) { cameraManagerGO = GameObject.FindGameObjectWithTag("CameraManager"); if (cameraManagerGO) { cameraManager = cameraManagerGO.GetComponent <CameraManager>(); } switch (scene.buildIndex) { case 0: // Title cinematicaInicio.Init(); PlayMusic(cinematicaInicio, MUSIC_TITLE_VOL); break; case 1: // Initial menu menuInicial.Init(); while (musicStack.Count > 0) { AudioManager.instance.StopMusic(musicStack.Pop()); FadeAudioSource(menuInicial.musicAudioSource, FadeAudio.FadeType.FadeIn, 5.0f, 1.0f, false); } PlayMusic(menuInicial, MUSIC_MENU_VOL); menuInicial.musicAudioSource.loop = true; StartCoroutine(SetMixerParameter("FXDiegeticEchoWetmix")); break; case 2: // Dungeon entrance player = GameObject.FindGameObjectWithTag("Player"); while (musicStack.Count > 0) { AudioManager.instance.StopMusic(musicStack.Pop()); } tutorial.Init(); PlayMusic(tutorial, MUSIC_TUTORIAL_VOL); FadeAudioSource(tutorial.musicAudioSource, FadeAudio.FadeType.FadeIn, 5.0f, 1.0f, false); tutorial.musicAudioSource.loop = true; StartCoroutine(SetMixerParameter("FXDiegeticEchoWetmix")); break; case 3: // Dungeon player = GameObject.FindGameObjectWithTag("Player"); currentState = State.WARMUP; currentWarmUpIndex = 0; while (musicStack.Count > 0) { AudioManager.instance.StopMusic(musicStack.Pop()); } warmUp[currentWarmUpIndex].Init(); PlayMusic(warmUp[currentWarmUpIndex], MUSIC_WARMUP_VOL); FadeAudioSource(warmUp[currentWarmUpIndex].musicAudioSource, FadeAudio.FadeType.FadeIn, 5.0f, 1.0f, false); StartCoroutine(SetMixerParameter("FXDiegeticEchoWetmix", CAVE_ECHO_WETMIX)); break; case 4: // Boss scene player = GameObject.FindGameObjectWithTag("Player"); currentState = State.BOSS; while (musicStack.Count > 0) { AudioManager.instance.StopMusic(musicStack.Pop()); } boss.Init(); if (boss.otherMusicAudioSources[0].isPlaying) { AudioManager.instance.FadeAudioSource(boss.otherMusicAudioSources[0], FadeAudio.FadeType.FadeOut, MUSIC_TRACK_FADEOUT_SHORT, FADEOUT_TARGET_VOLUME, false); } if (boss.otherMusicAudioSources[1].isPlaying) { AudioManager.instance.FadeAudioSource(boss.otherMusicAudioSources[1], FadeAudio.FadeType.FadeOut, MUSIC_TRACK_FADEOUT_SHORT, FADEOUT_TARGET_VOLUME, false); } PlayMusic(boss, MUSIC_BOSS_VOL); boss.musicAudioSource.loop = true; StartCoroutine(SetMixerParameter("FXDiegeticEchoWetmix", CAVE_ECHO_WETMIX)); break; // case 5: break; // End } }
void Update() { MusicPlay play; switch (currentState) { case State.WARMUP: if (player.transform.position.x > POSX_ENTER_KOREAN_MODE) { while (musicStack.Count > 0) { play = musicStack.Pop(); FadeAudioSource(play.audioSource, FadeAudio.FadeType.FadeOut, MUSIC_TRACK_FADEOUT_LONG, FADEOUT_TARGET_VOLUME, false); AudioManager.instance.Wait(MUSIC_TRACK_FADEOUT_LONG + 0.5f, () => { AudioManager.instance.StopMusic(play); }); } currentState = State.KOREAN_MODE; koreanMode.Init(); PlayMusic(koreanMode, MUSIC_KOREAN_VOL); koreanMode.musicAudioSource.loop = true; } else if (warmUp[currentWarmUpIndex].fadePoint <= warmUp[currentWarmUpIndex].musicAudioSource.timeSamples) { currentWarmUpIndex = (currentWarmUpIndex + 1) % 2; while (musicStack.Count > 0) { play = musicStack.Pop(); FadeAudioSource(play.audioSource, FadeAudio.FadeType.FadeOut, MUSIC_TRACK_FADEOUT_LONG, FADEOUT_TARGET_VOLUME, false); AudioManager.instance.Wait(MUSIC_TRACK_FADEOUT_LONG * 2, () => { AudioManager.instance.StopMusic(play); }); } warmUp[currentWarmUpIndex].Init(); PlayMusic(warmUp[currentWarmUpIndex], MUSIC_WARMUP_VOL); FadeAudioSource(warmUp[currentWarmUpIndex].musicAudioSource, FadeAudio.FadeType.FadeIn, MUSIC_TRACK_FADEOUT_LONG, 1.0f, false); } break; case State.KOREAN_MODE: if (player.transform.position.x > POSX_ENTER_LIFTABLE_PLATFORMS) { currentWarmUpIndex = 0; currentState = State.LIFTABLE_PLATFORMS; while (musicStack.Count > 0) { play = musicStack.Pop(); FadeAudioSource(play.audioSource, FadeAudio.FadeType.FadeOut, MUSIC_TRACK_FADEOUT_LONG, FADEOUT_TARGET_VOLUME, false); AudioManager.instance.Wait(MUSIC_TRACK_FADEOUT_LONG * 2, () => { AudioManager.instance.StopMusic(play); }); } liftablePlatforms[currentWarmUpIndex].Init(); PlayMusic(liftablePlatforms[currentWarmUpIndex], MUSIC_PLATFORMS_VOL); FadeAudioSource(liftablePlatforms[currentWarmUpIndex].musicAudioSource, FadeAudio.FadeType.FadeIn, MUSIC_TRACK_FADEOUT_LONG, 1.0f, false); } break; case State.LIFTABLE_PLATFORMS: if (liftablePlatforms[currentWarmUpIndex].fadePoint <= liftablePlatforms[currentWarmUpIndex].musicAudioSource.timeSamples) { currentWarmUpIndex = (currentWarmUpIndex + 1) % 2; while (musicStack.Count > 0) { play = musicStack.Pop(); FadeAudioSource(play.audioSource, FadeAudio.FadeType.FadeOut, MUSIC_TRACK_FADEOUT_LONG, FADEOUT_TARGET_VOLUME, false); AudioManager.instance.Wait(MUSIC_TRACK_FADEOUT_LONG * 2, () => { AudioManager.instance.StopMusic(play); }); } liftablePlatforms[currentWarmUpIndex].Init(); PlayMusic(liftablePlatforms[currentWarmUpIndex], MUSIC_PLATFORMS_VOL); FadeAudioSource(liftablePlatforms[currentWarmUpIndex].musicAudioSource, FadeAudio.FadeType.FadeIn, MUSIC_TRACK_FADEOUT_LONG, 1.0f, false); } break; case State.DEFEAT_BOSS: currentWarmUpIndex = 0; currentState = State.LIFTABLE_PLATFORMS; while (musicStack.Count > 0) { play = musicStack.Pop(); FadeAudioSource(play.audioSource, FadeAudio.FadeType.FadeOut, MUSIC_TRACK_FADEOUT_LONG, FADEOUT_TARGET_VOLUME, false); AudioManager.instance.Wait(MUSIC_TRACK_FADEOUT_LONG * 2, () => { AudioManager.instance.StopMusic(play); }); } liftablePlatforms[currentWarmUpIndex].Init(); PlayMusic(liftablePlatforms[currentWarmUpIndex], MUSIC_PLATFORMS_VOL); FadeAudioSource(liftablePlatforms[currentWarmUpIndex].musicAudioSource, FadeAudio.FadeType.FadeIn, MUSIC_TRACK_FADEOUT_LONG, 1.0f, false); break; case State.ENDING: while (musicStack.Count > 0) { play = musicStack.Pop(); FadeAudioSource(play.audioSource, FadeAudio.FadeType.FadeOut, MUSIC_TRACK_FADEOUT_SHORT, FADEOUT_TARGET_VOLUME, false); AudioManager.instance.Wait(MUSIC_TRACK_FADEOUT_LONG * 2, () => { AudioManager.instance.StopMusic(play); }); } currentState = State.CREDITS; AudioManager.instance.Wait(0.5f, () => { final.Init(); PlayMusic(final, MUSIC_ENDING_VOL); }); break; } }