| | 1 | | using System; |
| | 2 | | using DCL; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | internal class ThumbnailHandler : IDisposable |
| | 6 | | { |
| 0 | 7 | | public Texture2D texture { private set; get; } |
| | 8 | |
|
| | 9 | | AssetPromise_Texture texturePromise = null; |
| | 10 | |
|
| | 11 | | public void FetchThumbnail(string url, Action<Texture2D> onSuccess, Action onFail) |
| | 12 | | { |
| 12 | 13 | | if (!(texture is null)) |
| | 14 | | { |
| 0 | 15 | | onSuccess?.Invoke(texture); |
| 0 | 16 | | } |
| 12 | 17 | | else if (string.IsNullOrEmpty(url)) |
| | 18 | | { |
| 6 | 19 | | onFail?.Invoke(); |
| 6 | 20 | | } |
| 6 | 21 | | else if (texturePromise is null) |
| | 22 | | { |
| 6 | 23 | | texturePromise = new AssetPromise_Texture(url, storeTexAsNonReadable: false); |
| 6 | 24 | | texturePromise.OnSuccessEvent += textureAsset => |
| | 25 | | { |
| 0 | 26 | | texture = textureAsset.texture; |
| 0 | 27 | | onSuccess?.Invoke(texture); |
| 0 | 28 | | }; |
| 6 | 29 | | texturePromise.OnFailEvent += textureAsset => |
| | 30 | | { |
| 0 | 31 | | texturePromise = null; |
| 0 | 32 | | onFail?.Invoke(); |
| 0 | 33 | | }; |
| 6 | 34 | | AssetPromiseKeeper_Texture.i.Keep(texturePromise); |
| | 35 | | } |
| 6 | 36 | | } |
| | 37 | |
|
| | 38 | | public void Dispose() |
| | 39 | | { |
| 8 | 40 | | if (texturePromise != null) |
| | 41 | | { |
| 6 | 42 | | AssetPromiseKeeper_Texture.i.Forget(texturePromise); |
| 6 | 43 | | texturePromise = null; |
| | 44 | | } |
| 8 | 45 | | } |
| | 46 | | } |