public async Task LoadSceneAsync(string sceneName) { OnBeforeSceneChange.Invoke(_activeSceneLowLevelInfos.Scene); await UnloadActiveSceneAsync(); _activeSceneLowLevelInfos.Reset(); _activeSceneInfos = null; _activeSceneLowLevelInfos.SceneName = sceneName; _activeSceneLowLevelInfos.IsMenuScene = sceneName.ToLower().Contains("menu"); if (_activeSceneLowLevelInfos.IsMenuScene == false) { OnBeforeGameSceneLoad.Invoke(); } AsyncOperation op = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive); while (op.isDone == false) { _activeSceneLowLevelInfos.LoadProgress = op.progress * 0.7f; await Task.Delay(10); } _activeSceneLowLevelInfos.LoadProgress = 0.7f; Scene scene = SceneManager.GetSceneByName(sceneName); _activeSceneLowLevelInfos.SceneIndex = scene.buildIndex; _activeSceneLowLevelInfos.Scene = scene; SceneManager.SetActiveScene(scene); FindSceneInfos(ref scene); if (_activeSceneLowLevelInfos.IsMenuScene == false) { OnAfterGameSceneLoad.Invoke(_activeSceneLowLevelInfos.Scene); } OnAfterSceneChange.Invoke(_activeSceneLowLevelInfos.Scene); if (_activeSceneInfos != null) { while (_activeSceneInfos.LoadingComplete == false) { await Task.Delay(10); } } OnSceneLoadComplete.Invoke(_activeSceneLowLevelInfos.Scene); }
private async Task UnloadActiveSceneAsync() { if (_activeSceneLowLevelInfos.SceneLoaded == true) { if (_activeSceneLowLevelInfos.IsMenuScene == false) { OnBeforeGameSceneUnload.Invoke(_activeSceneLowLevelInfos.Scene); } AsyncOperation op = SceneManager.UnloadSceneAsync(_activeSceneLowLevelInfos.SceneIndex); while (op.isDone == false) { await Task.Delay(10); } _activeSceneLowLevelInfos.Reset(); _activeSceneInfos = null; if (_activeSceneLowLevelInfos.IsMenuScene == false) { OnAfterGameSceneUnload.Invoke(); } } }