static async void Req(string url) { using (UnityWebRequestAsync webRequestAsync = ETModel.ComponentFactory.Create <UnityWebRequestAsync>()) { await webRequestAsync.DownloadAsync(url); } }
public static async Task Req(string url, CallBack callback) { using (UnityWebRequestAsync webRequestAsync = ETModel.ComponentFactory.Create <UnityWebRequestAsync>()) { await webRequestAsync.DownloadAsync(url); callback(webRequestAsync.Request.downloadHandler.text); } }
static async public Task <Sprite> GetTextureFromUrl(string url) { // Log.Debug("url" + url); TaskCompletionSource <Sprite> tcs = new TaskCompletionSource <Sprite>(); using (UnityWebRequestAsync webRequestAsync = ETModel.ComponentFactory.Create <UnityWebRequestAsync>()) { await webRequestAsync.DownloadImageAsync(url); DownloadHandlerTexture downloadHandlerTexture = (DownloadHandlerTexture)webRequestAsync.Request.downloadHandler; Texture2D texture2D = downloadHandlerTexture.texture; Sprite sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), Vector2.zero); tcs.SetResult(sprite); } return(await tcs.Task); }