public SceneAsyncOption LoadLevelAdditive(string _sceneName, SceneType _type) { var async = new SceneAsyncOption(); currentSceneName = _sceneName; lastType = currentType; currentType = _type; StartCoroutine(Co_LoadScene(LoadSceneMode.Additive, async)); return(async); }
public SceneAsyncOption LoadLevel(string _sceneName, SceneType _type) { var async = new SceneAsyncOption(); currentSceneName = _sceneName; lastType = currentType; currentType = _type; SceneManager.LoadSceneAsync("Empty", LoadSceneMode.Single); async.progress = 0.1f; System.GC.Collect(); async.progress = 0.2f; Resources.UnloadUnusedAssets(); async.progress = 0.3f; StartCoroutine(Co_LoadScene(LoadSceneMode.Single, async)); return(async); }
IEnumerator Co_LoadScene(LoadSceneMode _mode, SceneAsyncOption _async) { var startProgress = _async.progress; var asyncOperation = SceneManager.LoadSceneAsync(currentSceneName, _mode); while (asyncOperation != null && !asyncOperation.isDone) { _async.progress = startProgress + asyncOperation.progress * 0.5f; yield return(null); } if (_mode == LoadSceneMode.Single) { System.GC.Collect(); Resources.UnloadUnusedAssets(); } _async.progress = 1f; _async.done = true; WDebug.Log(string.Format("Load {0} use<color=yellow> {1} </color>second", currentSceneName, _async.time)); }