Beispiel #1
0
 static async void Req(string url)
 {
     using (UnityWebRequestAsync webRequestAsync = ETModel.ComponentFactory.Create <UnityWebRequestAsync>())
     {
         await webRequestAsync.DownloadAsync(url);
     }
 }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        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);
        }