private IEnumerator waitForStringToLoad <TAsset>(AsyncAssetRequest <TAsset> assetRequest, AssetRequest <TextAsset> textRequest, string key, AssetLoadedHandler <TAsset> handler) where TAsset : class { yield return(textRequest); string text = textRequest.Asset.text; assetRequest.Request = new IndexedAssetRequest <TAsset>(key, (TAsset)(object)text); yield return(assetRequest); handler?.Invoke(key, (TAsset)(object)text); }
private static IEnumerator waitForLoadToFinish(string key, AssetRequest <TAsset> request, AssetLoadedHandler <TAsset> handler) { yield return(request); handler(key, request.Asset); }
private IEnumerator waitForStringToLoad <TAsset>(AsyncAssetRequest <TAsset> assetRequest, AssetRequest <string> stringRequest, string key, AssetLoadedHandler <TAsset> handler) where TAsset : class { yield return(stringRequest); string jsonString = stringRequest.Asset; JsonService json = Service.Get <JsonService>(); TAsset jsonAsset = json.Deserialize <TAsset>(jsonString); assetRequest.Request = new IndexedAssetRequest <TAsset>(key, jsonAsset); handler?.Invoke(key, jsonAsset); }
private IEnumerator waitForLoadToFinish <TAsset>(AssetRequest <TAsset> request, bool isSceneLoadRequest) where TAsset : class { int currentFrame = Time.frameCount; yield return(request); if (currentFrame == Time.frameCount) { yield return(null); } if (request.Cancelled) { yield break; } activeRequests.Remove(request.Key); if (!isSceneLoadRequest) { if (!assetIndex.IsReserved(request.Key)) { throw new InvalidOperationException("Asset key was not reserved in index: " + request.Key); } if (request.Asset == null) { assetIndex.Remove(request.Key); throw new InvalidOperationException("Asset failed to load for key: " + request.Key); } assetIndex.Add(request.Key, request.Asset); } List <string> exceptions = null; foreach (object item in activeRequestHandlers[request.Key]) { try { AssetLoadedHandler <TAsset> assetLoadedHandler = (AssetLoadedHandler <TAsset>)item; assetLoadedHandler(request.Key, request.Asset); } catch (Exception ex) { Log.LogError(this, "Asset request handler for key '" + request.Key + "' threw an exception: " + ex.Message); Log.LogException(this, ex); if (exceptions == null) { exceptions = new List <string>(); } exceptions.Add(ex.ToString()); } } activeRequestHandlers.Remove(request.Key); if (exceptions == null) { yield break; } StringBuilder stringBuilder = new StringBuilder("Asset request handler(s) for key '" + request.Key + "' threw one or more exceptions:\n"); foreach (string item2 in exceptions) { stringBuilder.AppendLine(); stringBuilder.AppendLine(item2); } throw new InvalidOperationException(stringBuilder.ToString()); }