/// <summary> /// 资源加载模块初始化 /// </summary> public override void init() { base.init(); // 初始化ABLoader和ABInfo可重用的基础数量 AssetBundleLoaderFactory.initialize(20); // 考虑到大部分都是采用同步加载,所以AssetBundleLoader并不需要初始化太多 AssetBundleInfoFactory.initialize(200); mAssetBundleDpMap = new Dictionary <string, string[]>(); ResLoadMode = ResourceLoadMode.AssetBundle; mABRequestTaskMap = new Dictionary <string, AssetBundleLoader>(); mUnsedABInfoList = new List <AbstractResourceInfo>(); // TODO: 根据设备设定相关参数,改成读表控制 mCheckUnsedABTimeInterval = 5.0f; mWaitForCheckUnsedABInterval = new WaitForSeconds(mCheckUnsedABTimeInterval); mMaxUnloadABNumberPerFrame = 10; mABMinimumLifeTime = 20.0f; mABRecycleFPSThreshold = 20; MaxMaximumAsyncCoroutine = 2; AssetBundleAsyncQueueList = new List <AssetBundleAsyncQueue>(); for (int i = 0; i < MaxMaximumAsyncCoroutine; i++) { var abaq = new AssetBundleAsyncQueue(); AssetBundleAsyncQueueList.Add(abaq); abaq.startABAsyncLoad(); } loadAllDpInfo(); }
/// <summary> /// 创建AssetBundleInfo对象信息 /// </summary> /// <param name="abname"></param> /// <param name="ab"></param> /// <returns></returns> public static AssetBundleInfo createAssetBundleInfo(string abname, AssetBundle ab) { var abi = AssetBundleInfoFactory.create(); abi.AssetBundleName = abname; abi.Bundle = ab; abi.onResourceUnloadedCallback = onABUnloaded; return(abi); }
/// <summary> /// 对应AB卸载回调 /// </summary> /// <param name="ari"></param> private static void onABUnloaded(AbstractResourceInfo ari) { var abi = ari as AssetBundleInfo; //AB卸载数据统计 if (ResourceLoadAnalyse.Singleton.ResourceLoadAnalyseSwitch) { ResourceLoadAnalyse.Singleton.addResourceUnloadedTime(abi.AssetBundleName); } // AB卸载时ABAssetBundleInfo回收时回收重用 AssetBundleInfoFactory.recycle(abi); }