예제 #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());
            }
        }
        /// <summary>
        /// 获得本类实例
        /// </summary>
        /// <returns></returns>
        public static ABManifestLoader GetInstance()
        {
            if (_Instance == null)
            {
                _Instance = new ABManifestLoader();
            }

            return(_Instance);
        }
        /// <summary>
        /// 下载 指定 AssetBundle 包
        /// </summary>
        /// <param name="sceneName"></param>
        /// <param name="abName"></param>
        /// <param name="loadAllComplete"></param>
        /// <returns></returns>
        public IEnumerator LoadAssetBundlePack(string sceneName, string abName, DelLoadComplete loadAllComplete)
        {
            // 参数检查
            if (string.IsNullOrEmpty(sceneName) == true || string.IsNullOrEmpty(abName) == true)
            {
                Debug.LogError(GetType() + "/LoadAssetBundlePack()/sceneName or   is null,请检查");

                yield return(null);
            }

            // 等待 Manifest 清单文件加载完成
            while (ABManifestLoader.GetInstance().IsLoadFinished == false)
            {
                yield return(null);
            }

            _ManifestObj = ABManifestLoader.GetInstance().GetABManifest();
            if (_ManifestObj == null)
            {
                Debug.LogError(GetType() + "/LoadAssetBundlePack()/_ManifestObj is null,请先确保加载 Manifest 清单文件");
                yield return(null);
            }

            if (_DicAllScenes.ContainsKey(sceneName) == false)
            {
                MultiABManager multiABManagerObj = new MultiABManager(sceneName, abName, loadAllComplete);
                _DicAllScenes.Add(sceneName, multiABManagerObj);
            }

            // 多包管理类
            MultiABManager tmpMultiABMgrObj = _DicAllScenes[sceneName];

            if (tmpMultiABMgrObj == null)
            {
                Debug.LogError(GetType() + "/LoadAssetBundlePack()/tmpMultiABMgrObj is null,请检查");
            }


            yield return(tmpMultiABMgrObj.LoadAssetBundle(abName));
        }
 private void Awake()
 {
     // 加载 Manifest 清单文件
     StartCoroutine(ABManifestLoader.GetInstance().LoadManifest());
 }