创建一个依赖关系的类 存放依赖项和被引用项
创建两个字典储存包 和 依赖关键 包名为key
然后就是递归加载 内部先处理好包依赖 最后统一加载
public IEnumerator LoadAssetBundle(string bundleName) { if (!_DicABRelation.ContainsKey(bundleName)) { _DicABRelation.Add(bundleName, new ABRelation(bundleName)); } yield return AddBundleDepend(bundleName); if (!_DicSingleABLoaderCache.ContainsKey(bundleName)) { Debug.Log("加载包 : "+bundleName); _CurrentSinglgABLoader = new SingleABLoader(bundleName, CompleteLoadAB); _DicSingleABLoaderCache.Add(bundleName, _CurrentSinglgABLoader); yield return _CurrentSinglgABLoader.LoadAssetBundle(); } } // 添加这个包所依赖其它包的信息 private IEnumerator AddBundleDepend(string bundleName) { var DependeInfo = ABManifestLoader.GetInstance().RetrivalDependce(bundleName); foreach (var dependBundleName in DependeInfo) { _DicABRelation[bundleName].AddDependence(dependBundleName); yield return AddBundleRefrence(bundleName,dependBundleName); } } // 添加这个包被引用的信息 private IEnumerator AddBundleRefrence(string bundleName, string dependBundleName) { if (!_DicABRelation.ContainsKey(dependBundleName)) { _DicABRelation.Add(dependBundleName, new ABRelation(dependBundleName)); Debug.Log("添加包引用 : "+ dependBundleName); yield return LoadAssetBundle(dependBundleName); } _DicABRelation[dependBundleName].AddReference(bundleName); }