/// <summary> /// Performs scene transition. /// </summary> /// <param name="config">Using <see cref="ChangeScene"/> or <see cref="AddScene"/> is recommended.</param> /// <returns></returns> protected async UniTask PerformSceneTransition <T>(SceneTransitionConfiguration <T> config) { if (config.PerformTransition && TransitionBackgroundController == null) { Debug.LogWarning( "Scene change / addition with a transition requested, " + "but there is no transition background attached.\n" + "Did you assign one in UniSwitcherInstaller?" ); } if (config.PerformTransition && TransitionBackgroundController != null) { while (TransitionBackgroundController.GetTransitionState() != TransitionState.Ready) { await UniTask.Yield(); } } if (!config.IsAdditive) { DontDestroyOnLoad(this); } if (!config.SupressProgressBar && sceneProgressBarController != null) { sceneProgressBarController.Enable(); sceneProgressBarController.SetDDoL(); } if (config.Delay <= 0.0001f) { // No delay or negligible delay if (config.PerformTransition && TransitionBackgroundController != null) { TransitionBackgroundController.TriggerTransitionIn(); await UniTask.Delay(TimeSpan.FromSeconds(0.1)); while (TransitionBackgroundController.GetTransitionState() == TransitionState.In) { await UniTask.Yield(); } } _sceneLoader.LoadScene(config.DestinationScene, config.IsAdditive, config.DataToTransfer); } else { _sceneLoader.LoadSceneWithDelay(config.DestinationScene, config.Delay, config.IsAdditive, config.DataToTransfer); if (config.PerformTransition && TransitionBackgroundController != null) { // In case of delayed transition, trigger transition 1 second before scene change TransitionBackgroundController.TriggerTransitionIn(); await UniTask.Delay(TimeSpan.FromSeconds(config.Delay - 1)); while (TransitionBackgroundController.GetTransitionState() == TransitionState.In) { await UniTask.Yield(); } } } while (!_sceneLoader.IsLoaded(config.DestinationScene) || (TransitionBackgroundController != null && config.PerformTransition && !TransitionBackgroundController.IsTransitionAllowed())) { await UniTask.Yield(); } TransitionBackgroundController?.DetectMainCamera(); var entryPointTask = _bootStrapper.TriggerEntryPoint(); while (entryPointTask.Status == UniTaskStatus.Pending) { await UniTask.Yield(); } if (!config.SupressProgressBar && sceneProgressBarController != null) { sceneProgressBarController.SetProgress(1f); if (config.IsAdditive) { sceneProgressBarController.Disable(); } else { sceneProgressBarController.Close().Forget(Debug.LogException); } } if (config.PerformTransition) { TransitionBackgroundController?.TriggerTransitionOut(); } if (!config.IsAdditive) { Destroy(gameObject); } }
/// <summary> /// Start the configuration as "Additive scene change," and attach data. /// </summary> /// <param name="scene"></param> /// <param name="data"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> protected SceneTransitionConfiguration <T> AddScene <T>(IScene scene, T data) { return(SceneTransitionConfiguration <T> .StartConfiguration(scene, true).AttachData(data)); }
/// <summary> /// Start the configuration as "Total scene change," and attach data. /// </summary> /// <param name="scene"></param> /// <param name="data"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> protected SceneTransitionConfiguration <T> ChangeScene <T>(IScene scene, T data) { return(SceneTransitionConfiguration <T> .StartConfiguration(scene, false).AttachData(data)); }
/// <summary> /// Start the configuration as "Additive scene change." /// You can directly pass this into <see cref="PerformSceneTransition{T}"/>. /// </summary> /// <param name="scene"></param> /// <returns></returns> protected SceneTransitionConfiguration <object> AddScene(IScene scene) { return(SceneTransitionConfiguration <object> .StartConfiguration(scene, true)); }
/// <summary> /// Start the configuration as "Total scene change." /// You can directly pass this into <see cref="PerformSceneTransition{T}"/>. /// </summary> /// <param name="scene"></param> /// <returns></returns> protected SceneTransitionConfiguration <object> ChangeScene(IScene scene) { return(SceneTransitionConfiguration <object> .StartConfiguration(scene, false)); }