AssetsBundleLoaderAsync FindAssetsBundleLoader(string assetBundleName) { AssetsBundleLoaderAsync tmpAbLoader = null; for (int i = 0, max = mAssetsBundleLoaderAsynList.Count; i < max; ++i) { if (mAssetsBundleLoaderAsynList[i].BundleName.Equals(assetBundleName)) { tmpAbLoader = mAssetsBundleLoaderAsynList[i]; break; } } return(tmpAbLoader); }
internal void Update(float deltaTime) { for (int i = mAssetsBundleLoaderAsynList.Count - 1; i >= 0; --i) { AssetsBundleLoaderAsync tmpAbLoader = mAssetsBundleLoaderAsynList[i]; if (tmpAbLoader.Update()) { mAssetsBundleLoaderAsynList.RemoveAt(i); tmpAbLoader.Dispose(); } } for (int i = mAssetsLoaderAsynList.Count - 1; i >= 0; --i) { AssetsLoaderAsync tmpAssetLoader = mAssetsLoaderAsynList[i]; if (tmpAssetLoader.Update()) { mAssetsLoaderAsynList.RemoveAt(i); tmpAssetLoader.Dispose(); } } }
public async Task LoadOneBundleAsync(string assetBundleName) { ABInfo abInfo; if (this.mLoadedBundles.TryGetValue(assetBundleName, out abInfo)) { ++abInfo.RefCount; return; } if (this.mLRUcacheDict.ContainsKey(assetBundleName)) { abInfo = this.mLRUcacheDict[assetBundleName]; ++abInfo.RefCount; this.mLoadedBundles[assetBundleName] = abInfo; this.mLRUcacheDict.Remove(assetBundleName); return; } AssetsBundleLoaderAsync tmpAbLoader = null; AssetsLoaderAsync tmpAssetsLoader = null; AssetBundle tmpAssetBundle = null; if (mLoadingBundles.TryGetValue(assetBundleName, out abInfo)) { ++abInfo.RefCount; tmpAbLoader = FindAssetsBundleLoader(assetBundleName); if (null != tmpAbLoader) { await tmpAbLoader.TcsAssetsBundle.Task; } tmpAssetsLoader = FindAssetsLoader(assetBundleName); if (null != tmpAssetsLoader) { await tmpAssetsLoader.TcsAssetLoaded.Task; } return; } abInfo = Game.ObjectPool.Fetch <ABInfo>(); abInfo.Init(assetBundleName, null); mLoadingBundles[assetBundleName] = abInfo; tmpAbLoader = Game.ObjectPool.Fetch <AssetsBundleLoaderAsync>(); mAssetsBundleLoaderAsynList.Add(tmpAbLoader); tmpAssetBundle = await tmpAbLoader.LoadAsync(assetBundleName); if (!tmpAssetBundle.isStreamedSceneAssetBundle) { // 异步load资源到内存cache住 tmpAssetsLoader = Game.ObjectPool.Fetch <AssetsLoaderAsync>(); tmpAssetsLoader.SetAssetBundle(tmpAssetBundle); mAssetsLoaderAsynList.Add(tmpAssetsLoader); UnityEngine.Object[] tmpAssets = await tmpAssetsLoader.LoadAllAssetsAsync(); //Logger.Log($"------------AssetBundleName = {assetBundleName}---------------"); foreach (UnityEngine.Object asset in tmpAssets) { string path = $"{assetBundleName}/{asset.name}".ToLower(); //Logger.Log($"assetName = {asset.name}"); this.mResourceCache[path] = asset; } //Logger.Log($"--------------------------------------------------------------"); } abInfo.AssetBundle = tmpAssetBundle; mLoadingBundles.Remove(assetBundleName); mLoadedBundles[assetBundleName] = abInfo; }