| | 1 | | using DCL; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | public class AirdroppingItemPanel : MonoBehaviour |
| | 7 | | { |
| | 8 | | [SerializeField] internal TextMeshProUGUI name; |
| | 9 | | [SerializeField] internal TextMeshProUGUI subtitle; |
| | 10 | | [SerializeField] internal Image thumbnail; |
| | 11 | |
|
| | 12 | | private string currentThumbnailUrl; |
| | 13 | | private AssetPromise_Texture currentThumbnailPromise; |
| | 14 | |
|
| | 15 | | public void SetData(string name, string subtitle, string thumbnailURL) |
| | 16 | | { |
| 7 | 17 | | this.name.text = name; |
| 7 | 18 | | this.name.gameObject.SetActive(!string.IsNullOrEmpty(this.name.text)); |
| | 19 | |
|
| 7 | 20 | | this.subtitle.text = subtitle; |
| 7 | 21 | | this.subtitle.gameObject.SetActive(!string.IsNullOrEmpty(this.subtitle.text)); |
| | 22 | |
|
| 7 | 23 | | currentThumbnailUrl = thumbnailURL; |
| | 24 | |
|
| 7 | 25 | | if (gameObject.activeInHierarchy) |
| 4 | 26 | | GetThumbnail(); |
| 7 | 27 | | } |
| | 28 | |
|
| 8 | 29 | | private void OnEnable() { GetThumbnail(); } |
| | 30 | |
|
| 8 | 31 | | private void OnDisable() { ForgetThumbnail(); } |
| | 32 | |
|
| | 33 | | public void ThumbnailReady(Asset_Texture texture) |
| | 34 | | { |
| 0 | 35 | | if (thumbnail.sprite != null) |
| 0 | 36 | | Destroy(thumbnail.sprite); |
| | 37 | |
|
| 0 | 38 | | thumbnail.sprite = ThumbnailsManager.CreateSpriteFromTexture(texture.texture); |
| 0 | 39 | | } |
| | 40 | |
|
| | 41 | | private void GetThumbnail() |
| | 42 | | { |
| 8 | 43 | | var newCurrentThumbnailPromise = ThumbnailsManager.GetThumbnail(currentThumbnailUrl, ThumbnailReady); |
| 8 | 44 | | ThumbnailsManager.ForgetThumbnail(currentThumbnailPromise); |
| 8 | 45 | | currentThumbnailPromise = newCurrentThumbnailPromise; |
| 8 | 46 | | } |
| | 47 | |
|
| | 48 | | private void ForgetThumbnail() |
| | 49 | | { |
| 4 | 50 | | if (currentThumbnailPromise == null) |
| 4 | 51 | | return; |
| | 52 | |
|
| 0 | 53 | | ThumbnailsManager.ForgetThumbnail(currentThumbnailPromise); |
| 0 | 54 | | ThumbnailReady(null); |
| 0 | 55 | | currentThumbnailPromise = null; |
| 0 | 56 | | } |
| | 57 | | } |