| | 1 | | using DCL; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | /// <summary> |
| | 7 | | /// It represents a Portable Experience item in the taskbar. |
| | 8 | | /// </summary> |
| | 9 | | public class PortableExperienceTaskbarItem : MonoBehaviour |
| | 10 | | { |
| | 11 | | [SerializeField] |
| | 12 | | private TaskbarButton button; |
| | 13 | |
|
| | 14 | | [SerializeField] |
| | 15 | | private TextMeshProUGUI tooltipText; |
| | 16 | |
|
| | 17 | | [SerializeField] |
| | 18 | | private CanvasGroup tooltipTextContainerCanasGroup; |
| | 19 | |
|
| | 20 | | [SerializeField] |
| | 21 | | private Image icon; |
| | 22 | |
|
| | 23 | | [SerializeField] |
| | 24 | | private GameObject loading; |
| | 25 | |
|
| | 26 | | [SerializeField] |
| | 27 | | private PortableExperienceContextMenu contextMenu; |
| | 28 | |
|
| 0 | 29 | | public TaskbarButton mainButton { get => button; } |
| | 30 | |
|
| | 31 | | internal void ConfigureItem( |
| | 32 | | string portableExperienceId, |
| | 33 | | string portableExperienceName, |
| | 34 | | string portableExperienceIconUrl, |
| | 35 | | TaskbarHUDController taskbarController) |
| | 36 | | { |
| 2 | 37 | | tooltipText.text = portableExperienceName; |
| 2 | 38 | | button.Initialize(); |
| 2 | 39 | | contextMenu.ConfigureMenu(portableExperienceId, portableExperienceName, taskbarController); |
| | 40 | |
|
| 2 | 41 | | if (!string.IsNullOrEmpty(portableExperienceIconUrl)) |
| | 42 | | { |
| 0 | 43 | | icon.enabled = false; |
| 0 | 44 | | loading.SetActive(true); |
| 0 | 45 | | ThumbnailsManager.GetThumbnail(portableExperienceIconUrl, OnIconReady); |
| | 46 | | } |
| 2 | 47 | | } |
| | 48 | |
|
| | 49 | | private void OnIconReady(Asset_Texture iconAsset) |
| | 50 | | { |
| 0 | 51 | | if (iconAsset != null) |
| | 52 | | { |
| 0 | 53 | | icon.sprite = ThumbnailsManager.CreateSpriteFromTexture(iconAsset.texture); |
| 0 | 54 | | icon.enabled = true; |
| 0 | 55 | | loading.SetActive(false); |
| | 56 | | } |
| 0 | 57 | | } |
| | 58 | |
|
| | 59 | | internal void ShowContextMenu(bool visible) |
| | 60 | | { |
| 0 | 61 | | tooltipTextContainerCanasGroup.alpha = visible ? 0f : 1f; |
| 0 | 62 | | contextMenu.ShowMenu(visible); |
| 0 | 63 | | } |
| | 64 | | } |