// Used for loading next level. IEnumerator LoadActiveAsync(SceneLoadInfo sceneToLoad, LoadSceneMode loadSceneMode) { List <AsyncOperation> toWaitFor = new List <AsyncOperation>(); foreach (string sceneName in sceneToLoad.sceneDefinition.ObjectReference.AllScenes) { if (!SceneManager.GetSceneByName(sceneName).isLoaded) { DevTools.Logger.Log(SceneServiceLog, "Loading {}", () => new object[] { sceneName }); toWaitFor.Add(SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive)); } } foreach (AsyncOperation asyncLevelUnload in toWaitFor) { yield return(asyncLevelUnload); } Scene primaryScene = SceneManager.GetSceneByName(sceneToLoad.sceneDefinition.ObjectReference.PrimaryScene); SceneManager.SetActiveScene(primaryScene); currentlyLoaded = sceneToLoad; // Use to change the state of the active scenes GameObjects before progressing (Loading scene save data ect.) OnPreFinishedLoading(); currentState = SceneLoadingState.Loaded; DevTools.Logger.Log(SceneServiceLog, "Finished Loading Scenes"); OnFinishedLoading(sceneToLoad); }
public Coroutine LoadScene(SceneLoadInfo sceneToLoad) { currentState = SceneLoadingState.Loading; OnLoadScene(sceneToLoad); if (currentlyLoaded == null) { return(owner.StartCoroutine(LoadActiveAsync(sceneToLoad, LoadSceneMode.Single))); } return(owner.StartCoroutine(UnloadAndLoadAsync(currentlyLoaded, sceneToLoad))); }