private IEnumerator TransitionCoroutine( GameScenes nextScene, SceneDataPack data, GameScenes[] additiveLoadScenes, bool autoMove ) { ToMoveFlag.Value = autoMove; _isTransitioning.Value = true; while (transitionComponent == null) { yield return(new WaitForSeconds(0.2f)); transitionComponent.threshold = 0; } //タッチイベントを吸収させる image.raycastTarget = true; transitionComponent.flip = false; transitionComponent.Play(); yield return(onTransactionFinishedInternal.FirstOrDefault().StartAsCoroutine()); transitionComponent.threshold = 1; SceneLoader.PreviousSceneData = data; //シーン遷移 yield return(SceneManager.LoadSceneAsync(nextScene.ToString(), LoadSceneMode.Single)); //追加シーンがある場合は一緒に読み込む if (additiveLoadScenes != null) { yield return(additiveLoadScenes.Select(scene => SceneManager.LoadSceneAsync(scene.ToString(), LoadSceneMode.Additive) .ObserveEveryValueChanged(x => x.isDone) .FirstOrDefault(x => x) ).WhenAll().StartAsCoroutine()); } Resources.UnloadUnusedAssets(); GC.Collect(); onAllSceneLoaded.OnNext(Unit.Default); if (!autoMove) { //自動遷移しないなら待機 yield return(ToMoveFlag.FirstOrDefault(x => x).StartAsCoroutine()); } ToMoveFlag.Value = false; //反転 transitionComponent.Play(); yield return(onTransactionFinishedInternal.FirstOrDefault().StartAsCoroutine()); image.raycastTarget = false; transitionComponent.threshold = 0; onTransitionAnimationFinishedSubject.OnNext(Unit.Default); _isTransitioning.Value = false; }
/// <summary> /// Transition coroutine. /// </summary> /// <returns>The coroutine.</returns> /// <param name="nextScene">Next scene.</param> /// <param name="sceneData">Scene data.</param> /// <param name="additiveLoadScenes">Additive load scenes.</param> /// <param name="autoTransition">If set to <c>true</c> auto transition.</param> private IEnumerator TransitionCoroutine( EScenes nextScene, SceneDataPackBase sceneData, EScenes[] additiveLoadScenes, bool autoTransition ) { isRunning = true; CanEndTransition.Value = autoTransition; if (fade == null) { Initialize(); yield return(null); } // Start transition. fade.FadeIn(1.0f); // Wait for transition animation. yield return(onTransitionFinishedInternal.FirstOrDefault().ToYieldInstruction()); // Set data what gave by previous scene. SceneLoader.PreviousSceneData = sceneData; // Load main scene as single scene. yield return(SceneManager.LoadSceneAsync(nextScene.ToString(), LoadSceneMode.Single)); // Load sub scenes. if (additiveLoadScenes != null) { yield return(additiveLoadScenes.Select(scene => SceneManager.LoadSceneAsync((int)scene, LoadSceneMode.Additive) .AsObservable()).WhenAll().ToYieldInstruction()); } yield return(null); // Release unused assets memories. Resources.UnloadUnusedAssets(); GC.Collect(); yield return(null); // Set current scene. currentGameScene = nextScene; // Publish notification of scene loaded. onAllSceneLoaded.OnNext(Unit.Default); if (!autoTransition) { // Wait for OpenLoadedNextScene function. yield return(CanEndTransition.FirstOrDefault(x => x).ToYieldInstruction()); } CanEndTransition.Value = false; // Start fadeout animation. fade.FadeOut(1.0f); // Wait for completed to open fade. yield return(onTransitionFinishedInternal.FirstOrDefault().ToYieldInstruction()); // Publish notification of finished scene transition. onTransitionAnimationFinishedSubject.OnNext(Unit.Default); isRunning = false; }