/// <summary> /// called when ONE scene is loaded (we need to wait for all others scene...) /// </summary> /// <param name="obj"></param> private void FirstSceneLoaded(AsyncOperation obj) { _asyncOperations.Remove(obj); if (_asyncOperations.Count == 0) { CalledWhenAllSceneAreLoaded(); } else { ExtCoroutineWithoutMonoBehaviour.StartUniqueCoroutine(WaitForLoading()); } }
public void LoadSceneFromLister(SceneContextAsset lister, FuncToCallOnComplete funcToCallOnComplete) { _isActivatingScene = true; _lastSceneAssetUsed = lister; _refFuncToCallOnComplete = funcToCallOnComplete; if (Application.isPlaying) { _asyncOperations.Clear(); for (int i = 0; i < _lastSceneAssetUsed.SceneToLoad.Count; i++) { if (i == 0) { SceneManager.LoadScene(_lastSceneAssetUsed.SceneToLoad[0].ScenePath, LoadSceneMode.Single); if (_lastSceneAssetUsed.SceneToLoad.Count == 1) { CalledWhenAllSceneAreLoaded(); return; } else { ExtCoroutineWithoutMonoBehaviour.StartUniqueCoroutine(WaitForLoading()); } } else { AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(_lastSceneAssetUsed.SceneToLoad[i].ScenePath, LoadSceneMode.Additive); asyncOperation.allowSceneActivation = false; asyncOperation.completed += OnSecondarySceneCompleted; _asyncOperations.Add(asyncOperation); } } } #if UNITY_EDITOR else { EditorUtility.DisplayProgressBar("Loading scene", "", 0f); for (int i = 0; i < _lastSceneAssetUsed.SceneToLoad.Count; i++) { if (_lastSceneAssetUsed.SceneToLoad[i].ScenePath.IsNullOrEmpty()) { continue; } EditorSceneManager.OpenScene(_lastSceneAssetUsed.SceneToLoad[i].ScenePath, (i == 0) ? OpenSceneMode.Single : OpenSceneMode.Additive); EditorUtility.DisplayProgressBar("Loading scene", "", i * 1 / _lastSceneAssetUsed.SceneToLoad.Count); } EditorUtility.ClearProgressBar(); CalledWhenAllSceneAreLoaded(); } #endif }