private void UnloadLevel(LevelScene level) { foreach (var scene in level.Collection.SceneReferences) { UnityEngine.SceneManagement.SceneManager.UnloadSceneAsync(scene); } }
// ReSharper disable once UnusedMember.Local private IEnumerator LoadCoroutine(SceneInfo info) { if (m_LastLevel != null && info.Level != m_LastLevel && m_LastLevel.Collection.TransitionScene.scenePath != "") { print("Transition"); AsyncOperation loadingLevel = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(m_LastLevel.Collection.TransitionScene.scenePath, LoadSceneMode.Additive); while (!loadingLevel.isDone) { yield return(new WaitForSeconds(2)); } } m_LastLevel = info.Level; AsyncOperation loading = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(info.Scene.Path(), info.Mode); while (!loading.isDone) { float percent = Mathf.Clamp01(loading.progress / .9f); LoadingEvent.Invoke(percent); yield return(null); } LoadingEvent.Invoke(0); }
// ReSharper disable once UnusedMember.Local private IEnumerator LoadAsyncLevel(LevelScene level) { if (m_LastLevel != null && level != m_LastLevel) { if (m_LastLevel.Collection.TransitionScene.scenePath != "") { var transition = m_LastLevel.Collection.TransitionScene; AsyncOperation loadingLevel = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(transition.scenePath, LoadSceneMode.Additive); while (!loadingLevel.isDone) { yield return(null); } if (transition.Mode == SceneCollection.TransitionSceneSettings.TransitionMode.Curve) { float time = 0; float max = transition.In.keys[transition.In.length - 1].time; while (time < max) { float value = transition.In.Evaluate(time); TransitionInEvent.Invoke(value); time += Time.deltaTime; yield return(0); } TransitionInEvent.Invoke(transition.In.Evaluate(transition.In.length - 1)); } } UnloadLevel(m_LastLevel); } int chunck = level.Collection.SceneReferences.Count; float percent = 0; for (int i = 0; i < chunck; i++) { var levelScene = level.Collection.SceneReferences[i]; var async = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(levelScene, LoadSceneMode.Additive); while (!async.isDone) { percent = Mathf.Clamp01(async.progress / .9f); LoadingEvent.Invoke((percent + i) / chunck); yield return(0); } } LoadingEvent.Invoke(1); if (m_LastLevel != null && level != m_LastLevel && m_LastLevel.Collection.TransitionScene.scenePath != "") { var transition = m_LastLevel.Collection.TransitionScene; if (transition.Mode == SceneCollection.TransitionSceneSettings.TransitionMode.Curve) { float time = 0; float max = transition.Out.keys[transition.Out.length - 1].time; while (time < max) { float value = transition.Out.Evaluate(time); TransitionOutEvent.Invoke(value); time += Time.deltaTime; yield return(null); } } UnityEngine.SceneManagement.SceneManager.UnloadSceneAsync(transition.scenePath); } m_LastLevel = level; LoadingEvent.Invoke(0); }
//public void LoadLevel(int levelIndex) //{ // LoadLevel(m_LevelCollectionEditor[levelIndex]); //} public static void LoadLevel(LevelScene level) { Instance.StartCoroutine("LoadAsyncLevel", level); }
// ReSharper disable once UnusedMember.Local public SceneInfo(LevelScene level, SceneStatesModel.SceneHandler scene, LoadSceneMode mode) : this() { Level = level; Scene = scene; Mode = mode; }