//---------------------------------------------------------------------- // private //---------------------------------------------------------------------- async UniTask LoadSceneWithFade( ISceneContext nextSceneContext, string nextSceneName, bool useCustomTransition, float fadeOutTime = 0.3f, float fadeInTime = 0.3f ) { if (isInTransition) { return; } isInTransition = true; sceneLoading?.Invoke(); if (currentSceneContext != null) { await currentSceneContext.Finalize(); } SetIsSceneReady(false); currentSceneContext = nextSceneContext; if (nextSceneContext != null) { await nextSceneContext.InitBeforeLoadScene(); } await SceneManager.LoadSceneAsync(nextSceneName); if (currentSceneContext != null) { await currentSceneContext.InitAfterLoadScene(); } SetIsSceneReady(true); sceneLoaded?.Invoke(); isInTransition = false; }
//---------------------------------------------------------------------- // private //---------------------------------------------------------------------- async UniTask LoadSceneWithFade( ISceneContext nextSceneContext, string nextSceneName, bool useCustomTransition, float fadeOutTime = 0.3f, float fadeInTime = 0.3f ) { if (isInTransition) { AltoLog.FW_Warn($"[SceneDirector] Now in transition - {nextSceneName} is dismissed."); return; } isInTransition = true; //----- 暗転と後片付け if (useCustomTransition && currentSceneContext != null) { await currentSceneContext.CustomFadeOut(); } else { await _screenFader.FadeOut(fadeOutTime); } sceneLoading?.Invoke(); DestroyAllObjectsInScene(); if (currentSceneContext != null) { await currentSceneContext.Finalize(); currentSceneContext.CancelTokenSource.Cancel(); } SetIsSceneReady(false); currentSceneContext = nextSceneContext; // 次のシーンに必要なリソースをロード、不要なものはアンロード await LoadAndUnloadResources(nextSceneContext); //----- 次のシーンの読み込み AltoLog.FW("[SceneDirector] - Init <b>Before</b> Load Scene"); if (nextSceneContext != null) { await nextSceneContext.InitBeforeLoadScene(); } await SceneManager.LoadSceneAsync(nextSceneName); DisableLocalAudioListener(); AltoLog.FW("[SceneDirector] - Init <b>After</b> Load Scene"); if (currentSceneContext != null) { await currentSceneContext.InitAfterLoadScene(); } SetIsSceneReady(true); sceneLoaded?.Invoke(); // シーンの 1 フレーム目は重くなるので 1 フレーム待ってからフェードイン await UniTask.DelayFrame(1); if (useCustomTransition && currentSceneContext != null) { await currentSceneContext.CustomFadeIn(); } else { await _screenFader.FadeIn(fadeInTime); } isInTransition = false; currentSceneContext?.OnStartupScene(); }