| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using System; |
| | 3 | | using System.Threading; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.Networking; |
| | 6 | |
|
| | 7 | | namespace DCL |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// Downloads Texture by Web URL |
| | 11 | | /// </summary> |
| | 12 | | public class AssetTextureWebLoader : ITextureAssetProvider |
| | 13 | | { |
| | 14 | | public async UniTask<Texture2D> GetTextureAsync(string url, CancellationToken cancellationToken = default) |
| | 15 | | { |
| 118 | 16 | | using var asyncOp = Environment.i.platform.webRequest.GetTexture(url, disposeOnCompleted: false); |
| | 17 | |
|
| 354 | 18 | | await asyncOp.WithCancellation(cancellationToken); |
| | 19 | |
|
| 107 | 20 | | if (!asyncOp.isSucceeded) |
| | 21 | | { |
| 4 | 22 | | var webRequestError = asyncOp.webRequest.error; |
| 4 | 23 | | throw new Exception($"Texture promise failed: {webRequestError} {url}"); |
| | 24 | | } |
| | 25 | |
|
| 103 | 26 | | return DownloadHandlerTexture.GetContent(asyncOp.webRequest); |
| 103 | 27 | | } |
| | 28 | |
|
| | 29 | | } |
| | 30 | | } |