private IEnumerator LoadSceneAsync(SceneProperties _scene) { previousScene = currentScene; currentScene = _scene; LoadingScreenProperties _loadingScreen = null; // if this scene have loading screen if (_scene.isLoadingScreen) { // if is anything in loading screens array if (loadingScreens.Count > 0) { // if scane loading screen indeks is in this array if (_scene.loadingScreenIndex < loadingScreens.Count) { _loadingScreen = loadingScreens[_scene.loadingScreenIndex]; } else // if not then set first loading screen { _loadingScreen = loadingScreens[0]; } } // if this scene is first in game dont fade out from previouse if (previousScene.scene != null) { // if nextscene has loading screen fadeOut from scene FadeOut(_loadingScreen); yield return(new WaitForSeconds(_loadingScreen.fadeOutDuration)); } } // load scene asynch AsyncOperation ao = SceneManager.LoadSceneAsync(_scene.buildIndex, _scene.loadSceneMode); // while loading while (!ao.isDone) { float progress = Mathf.Clamp01(ao.progress / 0.9f); //Debug.Log("Loading progress: " + (progress * 100) + "%"); // if is loading screen then push there progress e.g for progress bars if (_scene.isLoadingScreen) { _loadingScreen.OnLoading(progress); } yield return(null); } // if scene is loaded and has loading screen then FadeIn to scene if (_scene.isLoadingScreen) { FadeIn(_loadingScreen); } // close opened ui when loaded new scene if (_scene.closeAllUIScreenImmediately) { UIManager.Instance.CloseAllUIScreenImmediately(); } UIDebug.PrintDebug(UIDebug.DebugType.SCENE, transform, "UISceneManager", "LoadSceneAsync", "Scene loaded build index " + _scene.buildIndex + "."); // invoke event on loaded scene (open some new ui or something) _scene.OnSceneLoaded(); }
public void LoadScene(SceneProperties sceneProperties) { if (sceneProperties.buildIndex <= SceneManager.sceneCountInBuildSettings && sceneProperties.buildIndex >= 0) { //Debug.Log("Scene to load: " + sceneProperties.scene.name); UIDebug.PrintDebug(UIDebug.DebugType.SCENE, transform, "UISceneManager", "LoadScene", "Start loading scene build index " + sceneProperties.buildIndex + "."); StartCoroutine(LoadSceneAsync(sceneProperties)); } else { Debug.LogWarning("Can not load scene " + sceneProperties.scene.name + " because it is not added to Build Settings."); } }