/// <summary> /// 加载依赖的AB包 /// </summary> private IEnumerator LoadDependence(string abName, string refName) { ABRelation tempRelation; if (_abRelationDict.ContainsKey(abName)) { //要依赖的包的对应关系类存在,直接给它添加引用关系 tempRelation = _abRelationDict[abName]; tempRelation.AddReference(refName); } else { //没有就创建关系类 tempRelation = new ABRelation(abName); //为要依赖的包添加引用关系 tempRelation.AddReference(refName); //放入字典 _abRelationDict.Add(abName, tempRelation); //加载依赖的包(递归) yield return(LoadAssetBundle(abName)); } }
/// <summary> /// 加载AB包 /// </summary> public IEnumerator LoadAssetBundle(string abName) { //判断AB包关系类是否已存在 if (!_abRelationDict.ContainsKey(abName)) { //创建和AB包名对应的AB包关系类加入字典 ABRelation relation = new ABRelation(abName); _abRelationDict.Add(abName, relation); } //获取对应的关系类 ABRelation tempRelation = _abRelationDict[abName]; //得到指定AB包的所有依赖关系(查询清单文件) string[] dependenceArray = FrameworkEntry.ABManifestLoader.RetrivalDependece(abName); foreach (string itemDependence in dependenceArray) { //添加依赖项 tempRelation.AddDependence(itemDependence); //加载它依赖的包 yield return(LoadDependence(itemDependence, abName)); } //是否已经加载过 if (_singleABDict.ContainsKey(abName)) { yield return(_singleABDict[abName].LoadAssetBundle()); } else { //未加载过,创建对应的单包加载类对象 _curSingleAB = new SingleABLoader_2(_curFirstDirName, abName, CompleteLoadAB); _singleABDict.Add(abName, _curSingleAB); yield return(_curSingleAB.LoadAssetBundle()); } }