| | 1 | | using TMPro; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | /// <summary> |
| | 6 | | /// It represents the context menu for a Portable Experience item. |
| | 7 | | /// </summary> |
| | 8 | | public class PortableExperienceContextMenu : MonoBehaviour |
| | 9 | | { |
| | 10 | | [SerializeField] |
| | 11 | | private ShowHideAnimator menuAnimator; |
| | 12 | |
|
| | 13 | | [SerializeField] |
| | 14 | | private TextMeshProUGUI menuTitle; |
| | 15 | |
|
| | 16 | | [SerializeField] |
| | 17 | | private Button killButton; |
| | 18 | |
|
| | 19 | | private TaskbarHUDController taskbarController; |
| | 20 | | private string portableExperienceId; |
| | 21 | |
|
| | 22 | | internal void ConfigureMenu(string portableExperienceId, string portableExperienceName, TaskbarHUDController taskbar |
| | 23 | | { |
| 2 | 24 | | this.portableExperienceId = portableExperienceId; |
| 2 | 25 | | this.taskbarController = taskbarController; |
| | 26 | |
|
| 2 | 27 | | ShowMenu(false, true); |
| | 28 | |
|
| 2 | 29 | | menuTitle.text = portableExperienceName; |
| 2 | 30 | | killButton.onClick.AddListener(KillPortableExperience); |
| 2 | 31 | | } |
| | 32 | |
|
| 26 | 33 | | private void OnDestroy() { killButton.onClick.RemoveListener(KillPortableExperience); } |
| | 34 | |
|
| | 35 | | internal void ShowMenu(bool visible, bool instant = false) |
| | 36 | | { |
| 2 | 37 | | if (visible) |
| | 38 | | { |
| 0 | 39 | | if (!menuAnimator.gameObject.activeInHierarchy) |
| | 40 | | { |
| 0 | 41 | | menuAnimator.gameObject.SetActive(true); |
| | 42 | | } |
| | 43 | |
|
| 0 | 44 | | menuAnimator.Show(instant); |
| 0 | 45 | | } |
| | 46 | | else |
| | 47 | | { |
| 2 | 48 | | if (!menuAnimator.gameObject.activeInHierarchy) |
| | 49 | | { |
| 0 | 50 | | menuAnimator.gameObject.SetActive(false); |
| 0 | 51 | | } |
| | 52 | | else |
| | 53 | | { |
| 2 | 54 | | menuAnimator.Hide(instant); |
| | 55 | | } |
| | 56 | | } |
| 2 | 57 | | } |
| | 58 | |
|
| | 59 | | private void KillPortableExperience() |
| | 60 | | { |
| 0 | 61 | | taskbarController.KillPortableExperience(portableExperienceId); |
| 0 | 62 | | ShowMenu(false); |
| 0 | 63 | | } |
| | 64 | | } |