public static AssetAsyncRequest CreateBundleRequest( string bundleName, AssetBundleInfoNode assetBundleInfoNode, System.Action <string> bundleLoadedCallback, Dictionary <string, UnityEngine.Object> assetDic) { if (assetBundleInfoNode == null || string.IsNullOrEmpty(bundleName)) { Debug.LogError("Create asset request failed ::: Bundle name or asset bundle is null"); return(null); } AssetAsyncRequest request = new AssetAsyncRequest(); request.Reset(); request.assetRequestType = AssetRequestType.All; request.bundleName = bundleName; request.assetBundleInfoNode = assetBundleInfoNode; request.bundleLoadedCallback = bundleLoadedCallback; request.assetDic = assetDic; return(request); }
//追加异步请求 private void AppendRequest( string bundleName, AssetBundleInfoNode assetBundleInfoNode, string[] assets, System.Type type, System.Type[] types, string requester, System.Action <string> bundleCallback, System.Action <string, string[], System.Type[]> assetCallback, System.Action <string, string[], System.Type> assetCallbackSameType, Dictionary <string, UnityEngine.Object> assetDic) { AssetAsyncRequest req = null; if (assets != null && type != null) { req = AssetAsyncRequest.CreatePartRequest(bundleName, assetBundleInfoNode, assets, type, assetCallbackSameType, assetDic); } else if (assets != null && types != null) { req = AssetAsyncRequest.CreatePartRequest(bundleName, assetBundleInfoNode, assets, types, assetCallback, assetDic); } else { req = AssetAsyncRequest.CreateBundleRequest(bundleName, assetBundleInfoNode, bundleCallback, assetDic); } //加入异步加载队列 if (req != null) { asyncWaitingList.Add(req); if (DebugMode) { MgrLog(string.Format("Append async request... ==> {0}", asyncWaitingList.Count)); } } }
public static AssetAsyncRequest CreatePartRequest( string bundleName, AssetBundleInfoNode assetBundleInfoNode, string[] assetNameArray, System.Type assetType, System.Action <string, string[], System.Type> assetsLoadedCallbackSameType, Dictionary <string, UnityEngine.Object> assetDic) { if (assetBundleInfoNode == null || string.IsNullOrEmpty(bundleName)) { Debug.LogError("Create asset request failed ::: Bundle name or asset bundle is null"); return(null); } if (assetNameArray == null || assetType == null) { Debug.LogError("Create asset request failed"); return(null); } AssetAsyncRequest request = new AssetAsyncRequest(); request.Reset(); request.assetRequestType = AssetRequestType.Part_SameType; request.bundleName = bundleName; request.assetBundleInfoNode = assetBundleInfoNode; request.assetNameArray = assetNameArray; request.assetType = assetType; request.assetsLoadedCallbackSameType = assetsLoadedCallbackSameType; request.assetDic = assetDic; return(null); }
private IEnumerator PerformAsyncLoad(AssetAsyncRequest request) { AssetBundleRequest req = null; switch (request.assetRequestType) { case AssetRequestType.Part: for (int i = 0; i < request.assetTypeArray.Length; ++i) { req = request.assetBundleInfoNode.LoadAssetAsync(request.assetNameArray[i], request.assetTypeArray[i]); yield return(req); if (req.asset == null) { request.error = true; } else if (request.assetDic != null) { request.assetDic[request.assetNameArray[i]] = req.asset; } } break; case AssetRequestType.Part_SameType: for (int i = 0; i < request.assetTypeArray.Length; ++i) { req = request.assetBundleInfoNode.LoadAssetAsync(request.assetNameArray[i], request.assetType); yield return(req); if (req.asset == null) { request.error = true; } else if (request.assetDic != null) { request.assetDic[request.assetNameArray[i]] = req.asset; } } break; case AssetRequestType.All: req = request.assetBundleInfoNode.LoadAllAssetsAsync(); yield return(req); if (req.allAssets != null) { if (request.assetDic != null) { for (int j = 0; j < req.allAssets.Length; j++) { request.assetDic[req.allAssets[j].name] = req.allAssets[j]; } } } else { request.error = true; } break; default: break; } request.AssetsReady(); asyncLoadingList.Remove(request); }