/// <summary> /// 同步加载资源 /// </summary> private void loadAssetSync() { //通过资源名(即AB名)定位相关资源 var assetspath = AssetDatabase.GetAssetPathsFromAssetBundle(AssetBundleName); if (assetspath.Length == 0) { ResourceLogger.logErr(string.Format("找不到资源名 : {0}的资源!", AssetBundleName)); } else { mResourceInfo = createAssetDatabaseInfo(AssetBundleName, assetspath); mResourceInfo.updateLastUsedTime(); } ///AssetDatabase模式下没有依赖资源的概念, ///所以一口气回调资源加载任务完成和上层逻辑回调 LoadState = ResourceLoadState.SelfComplete; LoadSelfResourceCompleteNotifier(this); LoadSelfResourceCompleteNotifier = null; LoadState = ResourceLoadState.AllComplete; mResourceInfo.mIsReady = true; LoadResourceCompleteCallBack(mResourceInfo); LoadResourceCompleteCallBack = null; // 资源加载完成后,AssetDatabaseLoader的任务就完成了,回收重用 AssetDatabaseLoaderFactory.recycle(this); }
/// <summary> /// 创建AssetDatabase资源加载对象 /// </summary> /// <param name="resname">资源名</param> /// <returns></returns> private AssetDatabaseLoader createADLoader(string resname) { var adl = AssetDatabaseLoaderFactory.create(); adl.AssetBundlePath = resname; return(adl); }
/// <summary> /// 同步加载资源 /// </summary> private void loadAssetSync() { if (string.IsNullOrEmpty(AssetBundlePath)) { ResourceLogger.logErr(string.Format("找不到资源名 : {0}的资源!", AssetBundlePath)); } else { mResourceInfo = createAssetDatabaseInfo(AssetBundlePath); mResourceInfo.updateLastUsedTime(); } ///AssetDatabase模式下没有依赖资源的概念, ///所以一口气回调资源加载任务完成和上层逻辑回调 LoadState = ResourceLoadState.SelfComplete; LoadSelfResourceCompleteNotifier(this); LoadSelfResourceCompleteNotifier = null; LoadState = ResourceLoadState.AllComplete; mResourceInfo.mIsReady = true; LoadResourceCompleteCallBack(mResourceInfo); LoadResourceCompleteCallBack = null; // 资源加载完成后,AssetDatabaseLoader的任务就完成了,回收重用 AssetDatabaseLoaderFactory.recycle(this); }
/// <summary> /// 资源加载模块初始化 /// </summary> public override void init() { base.init(); ResLoadMode = ResourceLoadMode.AssetDatabase; mResourceRequestTaskMap = new Dictionary <string, AssetDatabaseLoader>(); mUnsedResourceInfoList = new List <AbstractResourceInfo>(); mCheckUnsedResourceTimeInterval = 5.0f; mWaitForCheckUnsedResourceInterval = new WaitForSeconds(mCheckUnsedResourceTimeInterval); mMaxUnloadResourceNumberPerFrame = 10; mResourceMinimumLifeTime = 20.0f; mResourceRecycleFPSThreshold = 20; AssetDatabaseLoaderFactory.initialize(20); // 考虑到大部分都是采用同步加载,所以AssetDatabaseLoader并不需要初始化太多 AssetDatabaseInfoFactory.initialize(200); }