/// <summary> /// 加载AB包 /// </summary> /// <param name="abName">AB包名</param> /// <returns></returns> public IEnumerator LoadAssetBundle(string abName) { if (!_DicABRelaton.ContainsKey(abName)) { ABRelation abRelationObj = new ABRelation(abName); _DicABRelaton.Add(abName, abRelationObj); } ABRelation tmpABRelationObj = _DicABRelaton[abName]; //得到指定AB包所有的依赖关系 string[] strDependenceArray = ABManifestLoader.GetInstance().RetrivalDependence(abName); foreach (string item_Dependence in strDependenceArray) { //添加依赖 tmpABRelationObj.AddDependence(item_Dependence); //添加引用 递归 yield return(LoadReference(item_Dependence, abName)); } //真正加载AB包 if (_DicSingleABLoaderCache.ContainsKey(abName)) { yield return(_DicSingleABLoaderCache[abName].LoadAssetBundle()); } else { _CurrentSingleABLoader = new SingleABLoader(abName, CompleteLoadAB); _DicSingleABLoaderCache.Add(abName, _CurrentSingleABLoader); yield return(_CurrentSingleABLoader.LoadAssetBundle()); } }
/// <summary> /// 下载AssetBundel 指定包 /// </summary> /// <param name="scenesName">场景名称</param> /// <param name="abName">AssetBundle 包名称</param> /// <param name="loadAllCompleteHandle">委托: 调用是否完成</param> /// <returns></returns> public IEnumerator LoadAssetBundlePack(string scenesName, string abName, DelLoadComplete loadAllCompleteHandle) { //参数检查 if (string.IsNullOrEmpty(scenesName) || string.IsNullOrEmpty(abName)) { Debug.LogError(GetType() + "/LoadAssetBundlePack()/ScenesName Or abName is null ,请检查!"); //yield return null;//类似于C#中的 continue 。 作用是跳过当前“帧” yield break; //类似于C# 中 return null; } //等待Manifest清单文件加载完成 while (!ABManifestLoader.GetInstance().IsLoadFinish) { yield return(null); } _ManifestObj = ABManifestLoader.GetInstance().GetABManifest(); if (_ManifestObj == null) { Debug.LogError(GetType() + "/LoadAssetBundlePack()/_ManifestObj is null ,请先确保加载Manifest清单文件!"); //yield return null; yield break; } //把当前场景加入集合中。 if (!_DicAllScenes.ContainsKey(scenesName)) { MultiABMgr multiMgrObj = new MultiABMgr(scenesName, abName, loadAllCompleteHandle); _DicAllScenes.Add(scenesName, multiMgrObj); } //调用下一层(“多包管理类”) MultiABMgr tmpMultiMgrObj = _DicAllScenes[scenesName]; if (tmpMultiMgrObj == null) { Debug.LogError(GetType() + "/LoadAssetBundlePack()/tmpMultiMgrObj is null ,请检查!"); } //调用“多包管理类”的加载指定AB包。 yield return(tmpMultiMgrObj.LoadAssetBundeler(abName)); }//Method_end
/// <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, DelLoadComplete loadAllCompleteHandle) { if (string.IsNullOrEmpty(sceneName) || string.IsNullOrEmpty(abName)) { Debug.LogError("sceneName:" + sceneName + ", abName:" + abName); yield break; } while (!ABManifestLoader.GetInstance().IsLoadFinish) { yield return(null); } _ManifestObj = ABManifestLoader.GetInstance().GetABManifest(); if (_ManifestObj == null) { Debug.LogError("_ManifestObj == null"); yield break; } //把当前场景加入集合中 if (!_DicAllScene.ContainsKey(sceneName)) { MultiABMgr multiABMgrObj = new MultiABMgr(sceneName, abName, loadAllCompleteHandle); _DicAllScene.Add(sceneName, multiABMgrObj); } //调用 多包管理类 MultiABMgr tmpMultiABMgrObj = _DicAllScene[sceneName]; if (tmpMultiABMgrObj == null) { Debug.LogError("tmpMultiABMgrObj == null"); yield break; } //加载指定AB包 yield return(tmpMultiABMgrObj.LoadAssetBundle(abName)); }
void Awake() { //加载Manifest清单文件 StartCoroutine(ABManifestLoader.GetInstance().LoadMainifestFile()); }