读取AssetBundle依赖关系清单文件(PlatformName.manifest)的单例辅助类
Наследование: IDisposable
Пример #1
0
        public IEnumerator LoadAssetBundle(string abName)
        {
            Debug.Log("Start load:" + abName);
            //已经加载过直接返回, 执行回调
            if (dicLoadCache.ContainsKey(abName))
            {
                CompleteLoadAB(abName);
                //yield return dicLoadCache[abName].LoadAssetBundle();
            }
            else
            {
                SingleAssetBundleLoader loader = new SingleAssetBundleLoader(abName, CompleteLoadAB);
                dicLoadCache.Add(abName, loader);
                //获取依赖关系
                string[] strDependeceArray = AssetBundleManifestLoader.GetInstance().GetDependce(abName);
                foreach (string item_depend in strDependeceArray)
                {
                    loader.Relation.AddDependence(item_depend);
                    //加载依赖项
                    yield return(LoadDepend(item_depend, loader));
                }

                yield return(loader.LoadAssetBundle());
            }
        }
Пример #2
0
        /// <summary>
        /// 加载AssetBundle的方法
        /// </summary>
        /// <param name="abName">要加载AssetBundle的名称</param>
        /// <returns></returns>
        public IEnumerator LoadAssetBundle(string abName) {
            // AssetBundle关系的建立
            if (!_relationDict.ContainsKey(abName)) {
                AssetBundleRelation relation = new AssetBundleRelation(abName);
                _relationDict.Add(abName, relation);
            }

            AssetBundleRelation tmpRelation = _relationDict[abName];
            // 获得所有的依赖关系
            string[] depend = AssetBundleManifestLoader.GetInstance().RetrivalDepend(abName);
            foreach (string itemDepend in depend) {
                tmpRelation.AddDepend(itemDepend); // 添加依赖项
                yield return LoadReference(itemDepend, abName); // 添加引用项
            }

            // 进行AssetBundle加载
            if (_loaderCacheDict.ContainsKey(abName)) { // 加载过了
                yield return _loaderCacheDict[abName].LoadABWWW(); // 加载AssetBundle
            }
            else {
                _currSingleAssetBundleLoader = new SingleAssetBundleLoader(abName, CompleteLoadSingle);
                _loaderCacheDict.Add(abName, _currSingleAssetBundleLoader);
                yield return _currSingleAssetBundleLoader.LoadABWWW();
            }

            yield return null;
        }
Пример #3
0
 public static AssetBundleManifestLoader GetInstance()
 {
     if (instance == null)
     {
         instance = new AssetBundleManifestLoader();
     }
     return(instance);
 }
        public IEnumerator LoadAssetBundlePack(string sceneName, string abName, ABLoadComplete loadComplete)
        {
            //循环等待manifest加载完成
            //TODO  需要优化(加载队列,回调)
            while (!AssetBundleManifestLoader.GetInstance().IsLoadFinish)
            {
                yield return(null);
            }
            mainfest = AssetBundleManifestLoader.GetInstance().GetMainfest();

            if (!dicAllScenes.ContainsKey(sceneName))
            {
                MultiABManager multiTmpManager = new MultiABManager(abName, loadComplete);
                dicAllScenes.Add(sceneName, multiTmpManager);
            }
            MultiABManager multiManager = dicAllScenes[sceneName];

            yield return(multiManager.LoadAssetBundle(abName));
        }
Пример #5
0
        /// <summary>
        /// 下载AssetBundle指定的包
        /// </summary>
        /// <param name="sceneName">场景名称</param>
        /// <param name="abName">AssetBundle名称</param>
        /// <param name="loadAllCompleteHandle">加载完成的委托</param>
        /// <returns></returns>
        public IEnumerator LoadAssetBundlePack(string sceneName, string abName, LoadComplete loadAllCompleteHandle)
        {
            // 参数检查
            if (string.IsNullOrEmpty(sceneName) || string.IsNullOrEmpty(abName))
            {
                Debug.LogError($"{GetType()}/LoadAssetBundlePack()方法传入的场景名称和包名称参数为空,无法加载");
                yield break;
            }

            // 等待Manifest加载完毕
            while (!AssetBundleManifestLoader.GetInstance().IsLoadFinish)
            {
                yield return(null);
            }

            // ab包中的所有依赖项
            _manifest = AssetBundleManifestLoader.GetInstance().GetAsstBundleManifest();
            if (_manifest == null)
            {
                Debug.LogError($"{GetType()}/LoadAssetBundlePack()方法_manifest为空,清单文件出现问题无法加载依赖项");
                yield break;
            }

            // 场景的包管理类加入到集合中
            if (!_sencesDict.ContainsKey(sceneName))
            {
                MultiAssetBundleManager multiMannger =
                    new MultiAssetBundleManager(sceneName, abName, loadAllCompleteHandle);
                _sencesDict.Add(sceneName, multiMannger);
            }

            // 获取多包管理类
            MultiAssetBundleManager multiManngerInDict = _sencesDict[sceneName];

            if (multiManngerInDict == null)
            {
                Debug.LogError($"{GetType()}/LoadAssetBundlePack()中multiManngerInDict为空,场景的多包管理类创建失败");
                yield break;
            }

            // 加载指定Ab包
            yield return(multiManngerInDict?.LoadAssetBundle(abName));
        }
 void Awake()
 {
     //加载Manifest清单文件
     StartCoroutine(AssetBundleManifestLoader.GetInstance().LoadMainifestFile());
 }
 /// <summary>
 /// AssetBundleManifestLoader单例获取方法
 /// </summary>
 /// <returns></returns>
 public static AssetBundleManifestLoader GetInstance() {
     return _instance ?? (_instance = new AssetBundleManifestLoader()); // 懒加载单例
 }