// /// <summary>完成指定包的调用</summary> // /// <param name="bundleName">指定的包名</param> // private void LoadComplete(string bundleName) { //// if(string.IsNullOrEmpty(bundleName)) //// throw new ArgumentException(FrameConst.PREFIX + nameof(bundleName)); // // if(bundleName.Equals(curBundleName)) // loadAllCompleteHandler?.Invoke(); // } /// <summary>加载依赖的AB包</summary> /// <param name="bundleName">指定的包名</param> private IEnumerator LoadDependence(string bundleName) { //AssetBundle包关系的建立 if(!bundleRelationDict.ContainsKey(bundleName)) bundleRelationDict.Add(bundleName, new BundleRelation(bundleName)); BundleRelation tempBundleRelation = bundleRelationDict[bundleName]; //得到指定AssetBundle包所有的依赖关系(查询相应的清单文件) string[] dependenceArray = ManifestMgr.Instance.RetrieveDependencies(bundleName); foreach(var dependenceItem in dependenceArray) { //添加依赖项 tempBundleRelation.AddABDependence(dependenceItem); //添加引用项(通过协程方法,递归调用) yield return LoadReference(dependenceItem, bundleName); } //真正加载AssetBundle包,并等待加载完成 if(singleBundleLoaderDict.ContainsKey(bundleName)) { yield return singleBundleLoaderDict[bundleName].LoadAssetBundle(); } else { //当前的SingleBundleLoader变成了下一个 curSingleBundleLoader = new SingleBundleLoader(bundleName,loadCompleteHandler); singleBundleLoaderDict.Add(bundleName, curSingleBundleLoader); yield return curSingleBundleLoader.LoadAssetBundle(); } }
/// <summary>加载引用的AB包</summary> /// <param name="bundleName">指定的包名</param> /// <param name="refBundleName">被引用的包名</param> private IEnumerator LoadReference(string bundleName, string refBundleName) { //如果包已经加载 if(bundleRelationDict.ContainsKey(bundleName)) { BundleRelation tempBundleRelation = bundleRelationDict[bundleName]; //添加AB包引用关系(被依赖) tempBundleRelation.AddReference(refBundleName); } //如果包未被加载 else { BundleRelation tempBundleRelation = new BundleRelation(bundleName); tempBundleRelation.AddReference(refBundleName); bundleRelationDict.Add(bundleName, tempBundleRelation); } //递归调用:开始加载所依赖的包 yield return LoadDependence(bundleName); }