| | 1 | | using System; |
| | 2 | | using DCL; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace NFTShape_Internal |
| | 6 | | { |
| | 7 | | public class NFTGifAsset : INFTAsset |
| | 8 | | { |
| 0 | 9 | | public bool isHQ => hqGifPromise != null; |
| 0 | 10 | | public int hqResolution { get; } |
| 0 | 11 | | public ITexture previewAsset => previewGif; |
| 0 | 12 | | public ITexture hqAsset => hqGifPromise?.asset; |
| | 13 | |
|
| | 14 | | private AssetPromise_Gif hqGifPromise; |
| | 15 | |
|
| | 16 | | private readonly GifPlayer gifPlayer; |
| | 17 | | private readonly Asset_Gif previewGif; |
| | 18 | |
|
| 0 | 19 | | public NFTGifAsset(Asset_Gif previewGif, int hqResolution, GifPlayer gifPlayer) |
| | 20 | | { |
| 0 | 21 | | this.previewGif = previewGif; |
| 0 | 22 | | this.hqResolution = hqResolution; |
| 0 | 23 | | this.gifPlayer = gifPlayer; |
| 0 | 24 | | } |
| | 25 | |
|
| | 26 | | public void Dispose() |
| | 27 | | { |
| 0 | 28 | | if (hqGifPromise != null) |
| | 29 | | { |
| 0 | 30 | | AssetPromiseKeeper_Gif.i.Forget(hqGifPromise); |
| 0 | 31 | | hqGifPromise = null; |
| | 32 | | } |
| 0 | 33 | | } |
| | 34 | |
|
| | 35 | | public void FetchAndSetHQAsset(string url, Action onSuccess, Action onFail) |
| | 36 | | { |
| 0 | 37 | | hqGifPromise = new AssetPromise_Gif(url); |
| | 38 | |
|
| 0 | 39 | | hqGifPromise.OnSuccessEvent += (asset) => |
| | 40 | | { |
| 0 | 41 | | gifPlayer?.SetGif(asset); |
| 0 | 42 | | onSuccess?.Invoke(); |
| 0 | 43 | | }; |
| 0 | 44 | | hqGifPromise.OnFailEvent += (asset) => |
| | 45 | | { |
| 0 | 46 | | hqGifPromise = null; |
| 0 | 47 | | onFail?.Invoke(); |
| 0 | 48 | | }; |
| | 49 | |
|
| 0 | 50 | | AssetPromiseKeeper_Gif.i.Keep(hqGifPromise); |
| 0 | 51 | | } |
| | 52 | |
|
| | 53 | | public void RestorePreviewAsset() |
| | 54 | | { |
| 0 | 55 | | gifPlayer?.SetGif(previewGif); |
| | 56 | |
|
| 0 | 57 | | if (hqGifPromise != null) |
| | 58 | | { |
| 0 | 59 | | AssetPromiseKeeper_Gif.i.Forget(hqGifPromise); |
| 0 | 60 | | hqGifPromise = null; |
| | 61 | | } |
| 0 | 62 | | } |
| | 63 | | } |
| | 64 | | } |