// 0=开始,1=ab头文件异步完成,开始加载内容,2=头文件完成,异步也完成 //public int ab_state; /// <summary> /// /// </summary> /// <param name="packageCnf">加载的AssetBundle包信息</param> public AssetBundleAsyncLoadOpertion(AssetBundlePackageCnf packageCnf) { if (packageCnf != null) { RequestResPath = packageCnf.PackagePath; _packageCnf = packageCnf; _bundlePath = packageCnf.FullPath; } }
public void UnLoad() { _abList.Clear(); LogManager.Assert(_assetbundle != null, "AssetBundleInfo UnLoad. AssetBundle不能为空:[{0}]", _cnf.PackagePath); if (_assetbundle != null) { _assetbundle.Unload(true); } _assetbundle = null; _cnf = null; }
public AssetBundleInfo InitAssetBundleInfo(AssetBundle assetbundle, AssetBundlePackageCnf packageCnf) { if (assetbundle == null) { return(null); } AssetBundleInfo packageInfo = new AssetBundleInfo(packageCnf); Object[] objs = assetbundle.LoadAllAssets(); packageInfo.InitAssetBundle(assetbundle, objs); _packageMap.Add(packageInfo.Path, packageInfo); return(packageInfo); }
// 内置同步加载指定路径的AssetBundle包 private AssetBundleInfo InternalSyncloadPackage(string packagePath) { // 1.已经在缓存中,引用+1 AssetBundleInfo packageInfo = GetPackageInfo(packagePath); if (packageInfo != null) { return(packageInfo); } // 2.如果已经在加载中,妈蛋老子只能等你了呗 if (_onLoadingAbPackage.Contains(packagePath)) { ResLog.Assert(!string.IsNullOrEmpty(packagePath), "主资源:[{0}],同步和异步同时加载,报错", packagePath); return(null); } // 3.如果在等待资源中直接剔除请求 int index = _onWaitAbPackage.IndexOf(packagePath); if (index > 0) { _onWaitAbPackage.RemoveAt(index); _waitToLoadRequest.RemoveAt(index); } // 4.加载AssetBundle资源 AssetBundlePackageCnf packageCnf = _mainInfo.GetPackageCnf(packagePath); if (packageCnf == null) { return(null); } AssetBundle assetbundle = AssetBundle.LoadFromFile(packageCnf.FullPath); ResLog.Assert(assetbundle != null, "同步加载AssetBundlePack失败,路径不存在:[{0}]", packageCnf.FullPath); if (assetbundle == null) { return(null); } // 5.初始化AssetBundle packageInfo = InitAssetBundleInfo(assetbundle, packageCnf); return(packageInfo); }
// 内置卸载指定路径的AssetBundle包 private bool InternalUnLoad(string packagePath, bool force = false) { // 1.得到AB包的配置信息 AssetBundlePackageCnf mainPackageCnf = _mainInfo.GetPackageCnf(packagePath); string mainPackagePath = mainPackageCnf.PackagePath; // 2.从缓存查找得到AssetBundle AssetBundleInfo packageInfo; _packageMap.TryGetValue(mainPackagePath, out packageInfo); ResLog.Assert(packageInfo != null, "AssetBundleLoader UnLoadAssetBundle 缓存中找不到对应的资源:[{0}]", mainPackagePath); if (packageInfo == null) { return(false); } // 3.这个AssetBundle的爸爸们还在,所以不能卸载 List <string> parentPaths = _mainInfo.GetParentPaths(mainPackagePath); if (parentPaths != null) { int length = parentPaths.Count; for (int i = 0; i < length; i++) { if (_packageMap.ContainsKey(parentPaths[i])) { return(false); } } } // 4.爸爸们已经不在了,看下内部的引用是否已经完全为0了 bool result = packageInfo.IsEmptyRef(); ResLog.Assert(!(force && !result), "AssetBundleLoader InternalUnLoad Error.主资源:[{0}]强制卸载但还有引用在引用数:", packagePath, packageInfo.RefCount); if (result || force) { packageInfo.UnLoad(); _packageMap.Remove(mainPackagePath); } return(result); }
// 内置异步加载指定路径的AssetBundle包 private ResLoadOpertion InternalAsyncLoadPackage(string packagePath) { AssetBundlePackageCnf packageCnf = _mainInfo.GetPackageCnf(packagePath); if (packageCnf == null) { return(null); } // 1.已经在缓存中,引用+1 AssetBundleInfo packageInfo = GetPackageInfo(packagePath); if (packageInfo != null) { AssetBundleCompleteLoadOperation operation = new AssetBundleCompleteLoadOperation(packageInfo); operation.OnUpdate(); return(operation); } // 2.如果已经在加载中,返回已经在加载中的结果 int index = _onLoadingAbPackage.IndexOf(packagePath); if (index >= 0) { ResLoadOpertion loadOperation = _onLoadingRequest[index]; return(loadOperation); } // 3.如果在等待中,返回等待中加载中的结果 index = _onWaitAbPackage.IndexOf(packagePath); if (index >= 0) { ResLoadOpertion loadOperation = _waitToLoadRequest[index]; return(loadOperation); } // 4得到Ab的包消息,并且添加到等待列表中 AssetBundleAsyncLoadOpertion packageOpertion = new AssetBundleAsyncLoadOpertion(packageCnf); _waitToLoadRequest.Add(packageOpertion); _onWaitAbPackage.Add(packagePath); return(packageOpertion); }
public void InitInfo() { _depMap.Clear(); _packageMap.Clear(); _resMap.Clear(); List <string[]> depResult = GetAbInfo(AssetBundleConst.AssetbundleDepPath); int length = depResult.Count; for (int i = 0; i < length; i++) { AssetBundleDepCnf dep = new AssetBundleDepCnf(); dep.InitInfo(depResult[i]); _depMap.Add(dep.AbName, dep); } InitReverseDep(); List <string[]> packageResult = GetAbInfo(AssetBundleConst.AssetbundlePackagePath); length = packageResult.Count; for (int i = 0; i < length; i++) { AssetBundlePackageCnf packageInfo = new AssetBundlePackageCnf(packageResult[i]); _packageMap.Add(packageInfo.PackagePath, packageInfo); } List <string[]> resResult = GetAbInfo(AssetBundleConst.AssetbundleResPath); length = resResult.Count; for (int i = 0; i < length; i++) { ResToAssetBundleCnf res = new ResToAssetBundleCnf(resResult[i]); _resMap.Add(res.ResPath, res); } }
public override void UnloadRequest() { base.UnloadRequest(); _request = null; _packageCnf = null; }
public AssetBundleInfo(AssetBundlePackageCnf cnf) { _cnf = cnf; RefCount = 0; }