public void Dispose(string bundleName) { if (!mNameBundleDict.ContainsKey(bundleName)) { Debug.LogError("没有加载" + bundleName + "无法加载"); return; } AssetBundleRelation assetBundleRelation = mNameBundleDict[bundleName]; string[] allDependences = assetBundleRelation.GetAllDependence(); foreach (var dependenceBundleName in allDependences) { AssetBundleRelation tempAssetBundleRelation = mNameBundleDict[bundleName]; bool resualt = tempAssetBundleRelation.RemoveReferenceBundle(bundleName); if (resualt) { //递归 Dispose(tempAssetBundleRelation.BundleName); } } //TODO:有错误 mNameBundleDict[bundleName].Dispose(); mNameBundleDict[bundleName] = null; }
/// <summary> /// 加载资源包 /// </summary> /// <param name="bundleName"></param> /// <param name="loadProgress"></param> /// <param name="loadAssetBundleCallback"></param> public void LoadAssetBundle(string bundleName, LoadProgress loadProgress, LoadAssetBundleCallback loadAssetBundleCallback) { if (mNameBundleDict.ContainsKey(bundleName)) { Debug.LogWarning("已经加载了" + bundleName); return; } AssetBundleRelation assetBundleRelation = new AssetBundleRelation(bundleName, loadProgress); mNameBundleDict.Add(bundleName, assetBundleRelation); loadAssetBundleCallback(mSceneName, bundleName); }
/// <summary> /// /// </summary> /// <param name="bundleName"></param> /// <param name="referenceBundleName"></param> /// <param name="loadProgress"></param> /// <returns></returns> private IEnumerator LoadDependence(string bundleName, string referenceBundleName, LoadProgress loadProgress) { if (mNameBundleDict.ContainsKey(bundleName)) { AssetBundleRelation assetBundleRelation = mNameBundleDict[bundleName]; assetBundleRelation.AddReferenceBundle(referenceBundleName); } else { AssetBundleRelation assetBundleRelation = new AssetBundleRelation(bundleName, loadProgress); assetBundleRelation.AddReferenceBundle(referenceBundleName); mNameBundleDict.Add(bundleName, assetBundleRelation); yield return(Load(bundleName)); } }
public IEnumerator Load(string bundleName) { while (!AssetBundleManifestLoader.Instance.Finish) { yield return(null); } AssetBundleRelation assetBundleRelation = mNameBundleDict[bundleName]; // assetBundleRelation.GetAllDependence(); string[] dependencesBundles = AssetBundleManifestLoader.Instance.GetDependences(bundleName); foreach (var item in dependencesBundles) { assetBundleRelation.AddDependence(item); yield return(LoadDependence(item, bundleName, assetBundleRelation.LoadProgress)); } yield return(assetBundleRelation.Load()); }