// 查看是否有依赖项 private string[] GetAbDependencies(string url) { // 加载的是 AssetBundle,没有依赖相 if (url.Equals(_assetBundleName) || url.Equals(_assetBundleName + GetExtension( ))) { return(null); } string urlExt = Path.GetExtension(url); if (urlExt != GetExtension( )) { url = url + GetExtension( ); } AssetBundleCache cb = this._cacheMgr.GetAssetBundle(_assetBundleName + GetExtension( )); if (cb == null) { throw new Exception(" Get AssetBundle is null"); } AssetBundleManifest manifest = cb.AB.LoadAsset("AssetBundleManifest") as AssetBundleManifest; if (manifest == null) { throw new Exception(" Get AssetBundleManifest is null"); } return(manifest.GetAllDependencies(url)); }
public void AsyncLoad(string url, AsyncLoadCallBack.CallBack onAsyncRequestCallBack, object context) { url = url + GetExtension( ); //UnityEngine.Debug.Log( string.Format( " ## {0}", url ) ); AssetBundleCache cab = _cacheMgr.GetAssetBundle(url); if (cab == null) { CreateRequest(url, onAsyncRequestCallBack, context); return; } // 缓存中已有AB数据,检查一下依赖项量是否完成(有可能正在加载) string[] dependsObj = GetAbDependencies(url); if (dependsObj == null) { // 没有依赖项,缓存中已有AB数据,直接回调 if (onAsyncRequestCallBack != null) { onAsyncRequestCallBack(context, cab.AB); } return; } // 遍历依赖项是否在缓存中 bool isOk = true; foreach (var one in dependsObj) { if (_cacheMgr.GetAssetBundle(one) != null) { continue; } isOk = false; break; } if (isOk) { // 缓存中有全部数据,直接回调 if (onAsyncRequestCallBack != null) { onAsyncRequestCallBack(context, cab.AB); } return; } // AB包不全,需要创建requset CreateRequest(url, onAsyncRequestCallBack, context); }
public AssetBundle GetAb(string url) { string urlExt = Path.GetExtension(url); if (urlExt != GetExtension( )) { url = url + GetExtension( ); } AssetBundleCache abCache = _cacheMgr.GetAssetBundle(url); if (abCache == null) { return(null); } return(abCache.AB); }
public void SetDontRelease(string url) { string urlExt = Path.GetExtension(url); if (urlExt != GetExtension( )) { url = url + GetExtension( ); } AssetBundleCache abCache = _cacheMgr.GetAssetBundle(url); if (abCache == null) { UnityEngine.Debug.Log(string.Format("!!!!! SetDontRelease failed. {0}", url)); return; } // todo 如果有依赖项,依赖项也需要DontRelease abCache.SetDontRelease( ); }