/// <summary> /// 加载AB包 /// </summary> /// <param name="abName"></param> /// <returns></returns> public IEnumerator LoadAssetBundles(string abName) { if (!_DicABRelation.ContainsKey(abName)) { ABRelation abRelationObj = new ABRelation(abName); _DicABRelation.Add(abName, abRelationObj); } ABRelation tmpABRelationObj = _DicABRelation[abName]; //得到指定AB包所有的依赖关系 string[] strDepencedArray = ABManifestLoader.GetInstance().RetrivalDependences(abName); foreach (string item_Depence in strDepencedArray) { //添加“依赖”项 tmpABRelationObj.AddDependence(item_Depence); //添加“引用”项 yield return(LoadReference(item_Depence, abName)); } //真正的AB包加载 if (_DicSingleABLoaderCache.ContainsKey(abName)) { yield return(_DicSingleABLoaderCache[abName].LoadAssetBundle()); } else { _CurrentSingleABLoader = new SingleABLoader(abName, CompletLoadAB); _DicSingleABLoaderCache.Add(abName, _CurrentSingleABLoader); yield return(_CurrentSingleABLoader.LoadAssetBundle()); } }//Method_end
/// <summary> /// 下载AssetBundle指定包 /// </summary> /// <param name="sceneName">场景名称</param> /// <param name="abName">AssetBundle名称</param> /// <param name="loadAllABCompleteHandle">AssetBundle名称</param> public IEnumerator LoadAssetBundlePackage(string sceneName, string abName, DelLoadComplete loadAllABCompleteHandle) { //参数检查 if (string.IsNullOrEmpty(sceneName) || string.IsNullOrEmpty(abName)) { Debug.LogError(GetType() + "/LoadAssetBundlePackage()/scenenName Or abName is Null ,请检查!"); yield return(null); } //等待Manifest清单加载完成 while (!ABManifestLoader.GetInstance().IsLoadFinish) { yield return(null); } //获取“AssetBundle(清单文件)系统类” _ManifestObj = ABManifestLoader.GetInstance().GetABManifest(); //参数检查 if (_ManifestObj == null) { Debug.LogError(GetType() + "/LoadAssetBundlePackage()/_ManifestObj==null,请先确保加载Manifest清单文件!"); yield return(null); } //如果不包含指定场景,则先创建 if (!_DicAllScenes.ContainsKey(sceneName)) { CreateScenesAB(sceneName, abName, loadAllABCompleteHandle); } //调用下一层(“多AssetBundle管理”类) MultiABMgr tmpMultiABMgrObj = _DicAllScenes[sceneName]; if (tmpMultiABMgrObj == null) { Debug.LogError(GetType() + "/LoadAssetBundlePackage()/tmpMultiABMgrObj==null , 请检查!"); } yield return(tmpMultiABMgrObj.LoadAssetBundles(abName)); }
private void Awake() { // 加载Manifest清单文件 StartCoroutine(ABManifestLoader.GetInstance().LoadManifestFile()); }