/// <summary> /// Load scenes in bundle /// </summary> private static void LoadScenes(SceneBundle bundle, bool hasToFullyReload, int persistantScenesCount) { //Get scenes in the bundle var scenes = bundle.GetScenes(); SceneManager.LoadScene(scenes[0], hasToFullyReload ? LoadSceneMode.Single : LoadSceneMode.Additive); setActiveScene = SceneManager.GetSceneAt(SceneManager.sceneCount - 1); //Get the loaded scene to set it as active later for (int i = 1; i < scenes.Length; i++) { SceneManager.LoadScene(scenes[i], LoadSceneMode.Additive); } if (persistantScenesCount >= 0) { //Check if persistant scenes are correctly loaded if (persistantScenesCount != currentSceneList.PersistantScenesBundle.ScenesCount) { //Re-open persistant scenes for (int i = 0; i < currentSceneList.PersistantScenesBundle.ScenesCount; i++) { SceneManager.LoadScene(currentSceneList.PersistantScenesBundle.GetSceneAtID(i), LoadSceneMode.Additive); } } } }
/// <summary> /// Async loading coroutine /// </summary> /// <param name="bundle"></param> /// <returns></returns> private static IEnumerator LoadingAsyncCoroutine(SceneBundle bundle, bool hasToFullyReload, int persistantScenesCount) { //Get scenes in the bundle var scenes = bundle.GetScenes(); AsyncOperation loadingOp; loadingOp = SceneManager.LoadSceneAsync(scenes[0], hasToFullyReload ? LoadSceneMode.Single : LoadSceneMode.Additive); yield return(loadingOp); setActiveScene = SceneManager.GetSceneAt(SceneManager.sceneCount - 1); //Get the loaded scene to set it as active later for (int i = 1; i < scenes.Length; i++) { loadingOp = SceneManager.LoadSceneAsync(scenes[i], LoadSceneMode.Additive); yield return(loadingOp); } if (persistantScenesCount >= 0) { //Check if persistant scenes are correctly loaded if (persistantScenesCount != currentSceneList.PersistantScenesBundle.ScenesCount) { //Re-open persistant scenes for (int i = 0; i < currentSceneList.PersistantScenesBundle.ScenesCount; i++) { loadingOp = SceneManager.LoadSceneAsync(currentSceneList.PersistantScenesBundle.GetSceneAtID(i), LoadSceneMode.Additive); yield return(loadingOp); } } } yield return(null); }