/// <summary> /// 异步加载场景 /// </summary> /// <param name="scenePath"></param> /// <param name="isAdditive"></param> /// <returns></returns> public IEnumerator LoadSceneAsync(string scenePath, bool isAdditive) { LoadSceneMode mode = isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single; string assetBundleName = mAssetManifest[scenePath]; string[] split = scenePath.Replace('\\', '/').Split('/'); string sceneName = split[split.Length - 1].Replace(".unity", ""); bool needLoadAssetBundle = !UnityUtility.IsSceneInBuildSetting(sceneName); if (needLoadAssetBundle) { IAsyncTask bundleTask = mAssetBundleHelper.LoadAssetBundleAsync(assetBundleName, null); while (bundleTask.Status != TaskStatus.Completed) { yield return(null); } } AsyncOperation operation = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName, mode); while (!operation.isDone) { yield return(null); } if (needLoadAssetBundle) { mAssetBundleHelper.Unload(assetBundleName); } }
/// <summary> /// 加载场景 /// </summary> /// <param name="scenePath"></param> /// <param name="isAdditive"></param> public void LoadScene(string scenePath, bool isAdditive) { LoadSceneMode mode = isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single; string assetBundleName = mAssetManifest[scenePath]; string[] split = scenePath.Replace('\\', '/').Split('/'); string sceneName = split[split.Length - 1].Replace(".unity", ""); if (!UnityUtility.IsSceneInBuildSetting(sceneName)) { AssetBundle assetBundle = mAssetBundleHelper.LoadAssetBundle(assetBundleName); UnityEngine.SceneManagement.SceneManager.LoadScene(sceneName, mode); mAssetBundleHelper.Unload(assetBundleName); } else { UnityEngine.SceneManagement.SceneManager.LoadScene(sceneName, mode); } }