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