Example #1
0
        private static IEnumerator _LoadScene(string sceneName, bool additive, bool forceLoad)
        {
            while (IsLoadingScene)
            {
                yield return(null);
            }

            if (CurrentScene == sceneName && !forceLoad)
            {
                yield break;
            }

            IsLoadingScene = true;

            // check to see if this is in a bundle or not
            AssetBundle    bundle    = null;
            AssetSceneInfo sceneInfo = null;

            if (_scenes.TryGetValue(sceneName, out sceneInfo))
            {
                Loader.CachedLoadHandler loader = new Loader.CachedLoadHandler(Loader.GetBundlePath(sceneInfo.packId, Loader.GetSceneBundleName(sceneInfo.id)), true, sceneInfo.ts);
                Coroutine coroutine             = loader.Load();
                if (loader.assetBundle == null)
                {
                    yield return(coroutine);
                }
                bundle = loader.assetBundle;
            }

            if (additive)
            {
                _loadLevelOperation = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName, UnityEngine.SceneManagement.LoadSceneMode.Additive);
                while (!_loadLevelOperation.isDone)
                {
                    yield return(_loadLevelOperation);
                }
            }
            else
            {
                _loadLevelOperation = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName, UnityEngine.SceneManagement.LoadSceneMode.Single);
                while (!_loadLevelOperation.isDone)
                {
                    yield return(_loadLevelOperation);
                }
            }

            CurrentScene = sceneName;

            if (bundle != null)
            {
#if ENABLE_LOGGING
                EB.Debug.LogCoreAsset("<color=#ff0000>910_释放AssetBundle</color>" + sceneName);
#endif
                bundle.Unload(false);
                FixupEditorMaterials();
            }

            IsLoadingScene = false;
        }
Example #2
0
        /// <summary>
        /// 加载AssetBundle,Bundle的加载是同步
        /// </summary>
        /// <param name="loadList">需要加载的列表</param>
        /// <param name="reqTimestamp"></param>
        /// <returns></returns>
        private static IEnumerator _LoadBundles(List <AssetBundleInfo> loadList, long reqTimestamp = 0)
        {
            WaitForFixedUpdate wait = new WaitForFixedUpdate();

            for (int i = 0; i < loadList.Count; i++)
            {
                AssetBundleInfo info = loadList[i];
                info.unload = false; // make sure we don't try to unload this

                if (!info.isLoaded)
                {
                    // see if we can start this load
                    if (!string.IsNullOrEmpty(info.parent) && !IsBundleLoaded(info.parent))
                    {
                        continue;
                    }

                    #region 加载AssetBundle
                    if (info.uncompressed)  // try and load off disk, if it's not already loading via WWW
                    {
                        var baseURL = "";
                        baseURL = Loader.GetBaseURL(info.packId);
                        var bundlePath = Loader.GetBundlePath(info.id);
                        var path       = baseURL + bundlePath;
                        Loader.CachedLoadHandler loader = new Loader.CachedLoadHandler(path, true, reqTimestamp);
                        Coroutine coroutine             = loader.Load();
                        if (loader.assetBundle == null)
                        {
                            yield return(coroutine);
                        }
                        //
#if ENABLE_LOGGING
                        EB.Debug.LogCoreAsset("加载好_指定的AssetBundle,路径:<color=#00ff00>{0}</color>", path);
#endif
                        info.bundle = loader.assetBundle;

                        if (!info.isLoaded)
                        {
                            FatalLoadError(info);
                            break;
                        }
                        else
                        {
                            info.bundle.name = info.id;
                        }
                    }
                    #endregion
                }
            }
        }