Ejemplo n.º 1
0
        /// <summary>
        /// 加载 AB 包(包括依赖项)
        /// </summary>
        /// <param name="abName"></param>
        /// <returns></returns>
        public IEnumerator LoadAssetBundle(string abName)
        {
            // AB 包关系的建立
            if (_DicABRelation.ContainsKey(abName) == false)
            {
                ABRelation abRelationObj = new ABRelation(abName);
                _DicABRelation.Add(abName, abRelationObj);
            }

            ABRelation tmpABRelationObj = _DicABRelation[abName];

            // 得到指定AB所有的依赖关系(查询Manifest清单文件)
            string[] strDependencyArray = ABManifestLoader.GetInstance().RetrivalDependency(abName);
            foreach (string item_Dependency in strDependencyArray)
            {
                // 添加“依赖项”
                tmpABRelationObj.AddDependency(item_Dependency);
                // 添加引用(背以来) (方便递归调用)
                yield return(LoadReference(item_Dependency, abName));
            }

            // 真正加载 AB 包
            if (_DicSingleABLoaderCache.ContainsKey(abName) == true)
            {
                yield return(_DicSingleABLoaderCache[abName].LoadAssetBundle());
            }
            else
            {
                _CurrentSingleABLoader = new SingleABLoader(abName, CompleteLoadAB);
                _DicSingleABLoaderCache.Add(abName, _CurrentSingleABLoader);
                yield return(_CurrentSingleABLoader.LoadAssetBundle());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 加载应用 AB 包
        /// </summary>
        /// <param name="abName">AB 包名称</param>
        /// <param name="refABName">被引用AB包名称</param>
        /// <returns></returns>
        private IEnumerator LoadReference(string abName, string refABName)
        {
            // AB 包已经加载了
            if (_DicABRelation.ContainsKey(abName))
            {
                ABRelation tmpABRelationObj = _DicABRelation[abName];

                // 添加AB包引用关系(被依赖关系)
                tmpABRelationObj.AddReference(refABName);
            }
            else
            {
                ABRelation tmpABRelationObj = new ABRelation(abName);
                tmpABRelationObj.AddReference(refABName);
                _DicABRelation.Add(abName, tmpABRelationObj);


                // 开始加载依赖的包(一个递归调用)
                yield return(LoadAssetBundle(abName));
            }
        }