private void CommenceLoading(SceneReference targetScene) { FadeToBlack().Then(() => { SceneManager.SetActiveScene(SceneManager.GetSceneByPath(BaseScene.SceneName)); }).Then( () => LoadScene(LoadingScreen) ).Then( UnfadeFromBlack ).Then( UnloadStrayScenes ).Then( () => LoadScene(targetScene) ).Then( FadeToBlack ).Then( () => UnloadScene(LoadingScreen) ).Then(() => { SceneManager.SetActiveScene(SceneManager.GetSceneByPath(targetScene.SceneName)); }).Then( UnfadeFromBlack ).Then ( () => EndLoadScene() ); }
public void StartLoadScene(SceneReference desiredScene, bool force = false) { if (_isLoading) { return; } BaseGame.Instance.SwitchStateImmediate <GameLoadingScreenState>(); _nextScene = desiredScene; if (_isLoading || (!force && SceneManager.GetActiveScene().path == desiredScene)) { Debug.LogFormat("Scene '{0}' already loaded!", desiredScene); EndLoadScene(already_loaded: true); return; } _isLoading = true; Debug.LogFormat("Loading scene '{0}' ...", desiredScene); // StartCoroutine(ExecuteLoading(i, () => EndLoadScene())); CommenceLoading(desiredScene); }
private void EndLoadScene(bool already_loaded = false) { CurrentScene = _nextScene; if (!already_loaded) { Debug.Log("Loaded scene " + SceneManager.GetActiveScene().buildIndex + "!"); } if (OnSceneLoad != null) { OnSceneLoad(); } _isLoading = false; }
private void CommenceLoading(SceneReference targetScene) { FadeToBlack().Then(() => { SceneManager.SetActiveScene(SceneManager.GetSceneByPath(BaseScene.SceneName)); }).Then(() => { gameObject.BroadcastToAll("PreOnLoadingScreenOn"); }).Then( () => LoadScene(LoadingScreen) ).Then(() => { gameObject.BroadcastToAll("PostOnLoadingScreenOn"); }).Then( UnfadeFromBlack ).Then( UnloadStrayScenes ).Then( () => LoadScene(targetScene) ).Then(() => { gameObject.BroadcastToAll("PreOnLoadingScreenOff"); }).Then( FadeToBlack ).Then( () => UnloadScene(LoadingScreen) ).Then(() => { gameObject.BroadcastToAll("PostOnLoadingScreenOff"); SceneManager.SetActiveScene(SceneManager.GetSceneByPath(targetScene.SceneName)); }).Then( UnfadeFromBlack ).Then ( () => EndLoadScene() ).Catch(exception => { Debug.LogError($"Scene loading failed with following exception: {exception.ToString()}"); }); }