void LoadNewLevelAsync(string LevelPath) { //Notify our listeners that we are loading a new scene. It is now valid to get current level to check which scene is loading. OnLoadingSceneBegin?.Invoke(); /* Async Scene Loading with Additive mode. This will load a scene on top of our current scene, meaning it will not destoy the gameobjects that are in our "Main Scene" Where the GameSceneManager lives * Subscribe to complete event on the async action to notify us when the loading is complete. * This is hardly useful for a project of this size. Our levels will load in fractions of a second but useful for larger level setups */ AsyncOperation sceneloading = SceneManager.LoadSceneAsync(LevelPath, LoadSceneMode.Additive); sceneloading.completed += OnSceneLoadCompleted; }
private IEnumerator LoadScene(int sceneIndex) { isLoadingScene = true; OnLoadingSceneBegin?.Invoke(); if (CurrentLevel != NoLevel && CurrentLevel != sceneIndex) { yield return(SceneManager.UnloadSceneAsync(CurrentLevel)); } yield return(SceneManager.LoadSceneAsync(sceneIndex, LoadSceneMode.Additive)); isLoadingScene = false; CurrentLevel = sceneIndex; OnLoadingSceneComplete?.Invoke(); }