| | 1 | | using DCL; |
| | 2 | | using DCL.Configuration; |
| | 3 | | using System; |
| | 4 | | using System.Collections; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using TMPro; |
| | 7 | | using UnityEngine; |
| | 8 | | using UnityEngine.UI; |
| | 9 | |
|
| | 10 | | public class CatalogAssetPackAdapter : MonoBehaviour |
| | 11 | | { |
| | 12 | | public TextMeshProUGUI titleTxt; |
| | 13 | | public RawImage packImg; |
| | 14 | | public Texture collectiblesSprite; |
| | 15 | |
|
| | 16 | | public event Action<CatalogItemPack> OnCatalogItemPackClick; |
| | 17 | | CatalogItemPack catalogItemPack; |
| | 18 | |
|
| | 19 | | string loadedThumbnailURL; |
| | 20 | | AssetPromise_Texture loadedThumbnailPromise; |
| | 21 | | public void SetContent(CatalogItemPack catalogItemPack) |
| | 22 | | { |
| 0 | 23 | | this.catalogItemPack = catalogItemPack; |
| 0 | 24 | | titleTxt.text = this.catalogItemPack.title; |
| | 25 | |
|
| 0 | 26 | | if (catalogItemPack.id != BIWSettings.ASSETS_COLLECTIBLES) |
| | 27 | | { |
| 0 | 28 | | GetThumbnail(); |
| 0 | 29 | | } |
| | 30 | | else |
| | 31 | | { |
| 0 | 32 | | packImg.enabled = true; |
| 0 | 33 | | packImg.texture = collectiblesSprite; |
| | 34 | | } |
| 0 | 35 | | } |
| | 36 | |
|
| | 37 | | private void GetThumbnail() |
| | 38 | | { |
| 0 | 39 | | var url = catalogItemPack?.GetThumbnailUrl(); |
| | 40 | |
|
| 0 | 41 | | if (url == loadedThumbnailURL) |
| 0 | 42 | | return; |
| | 43 | |
|
| 0 | 44 | | if (catalogItemPack == null || string.IsNullOrEmpty(url)) |
| 0 | 45 | | return; |
| | 46 | |
|
| 0 | 47 | | string newLoadedThumbnailURL = url; |
| 0 | 48 | | var newLoadedThumbnailPromise = new AssetPromise_Texture(url); |
| | 49 | |
|
| | 50 | |
|
| 0 | 51 | | newLoadedThumbnailPromise.OnSuccessEvent += SetThumbnail; |
| 0 | 52 | | newLoadedThumbnailPromise.OnFailEvent += (x, error) => { Debug.Log($"Error downloading: {url}, Exception: {error |
| | 53 | |
|
| 0 | 54 | | AssetPromiseKeeper_Texture.i.Keep(newLoadedThumbnailPromise); |
| | 55 | |
|
| | 56 | |
|
| 0 | 57 | | AssetPromiseKeeper_Texture.i.Forget(loadedThumbnailPromise); |
| 0 | 58 | | loadedThumbnailPromise = newLoadedThumbnailPromise; |
| 0 | 59 | | loadedThumbnailURL = newLoadedThumbnailURL; |
| 0 | 60 | | } |
| | 61 | |
|
| | 62 | | public void SetThumbnail(Asset_Texture texture) |
| | 63 | | { |
| 0 | 64 | | if (packImg != null) |
| | 65 | | { |
| 0 | 66 | | packImg.enabled = true; |
| 0 | 67 | | packImg.texture = texture.texture; |
| | 68 | | } |
| 0 | 69 | | } |
| | 70 | |
|
| 0 | 71 | | public void SceneAssetPackClick() { OnCatalogItemPackClick?.Invoke(catalogItemPack); } |
| | 72 | | } |