| | 1 | | using DCL; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using TMPro; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | public class TaskbarMoreMenuButton : MonoBehaviour |
| | 8 | | { |
| | 9 | | internal enum AnimationStatus |
| | 10 | | { |
| | 11 | | Hide = 0, |
| | 12 | | Visible = 1, |
| | 13 | | In = 2, |
| | 14 | | Out = 3, |
| | 15 | | } |
| | 16 | |
|
| | 17 | | [SerializeField] public Button mainButton; |
| | 18 | | [SerializeField] internal TMP_Text buttonText; |
| | 19 | | [SerializeField] internal Animator buttonAnimator; |
| | 20 | | [SerializeField] internal Color notInteractableColor; |
| | 21 | | [SerializeField] internal List<AppMode> compatibleModes; |
| | 22 | |
|
| 0 | 23 | | internal AnimationStatus lastPlayedAnimation { get; private set; } = AnimationStatus.Hide; |
| | 24 | |
|
| | 25 | | private Color originalTextColor; |
| | 26 | |
|
| | 27 | | private void Start() |
| | 28 | | { |
| 70 | 29 | | if (buttonText != null) |
| 70 | 30 | | originalTextColor = buttonText.color; |
| | 31 | |
|
| 70 | 32 | | DataStore.i.appMode.OnChange += AppMode_OnChange; |
| 70 | 33 | | AppMode_OnChange(DataStore.i.appMode.Get(), AppMode.DEFAULT); |
| 70 | 34 | | } |
| | 35 | |
|
| 198 | 36 | | private void OnDestroy() { DataStore.i.appMode.OnChange -= AppMode_OnChange; } |
| | 37 | |
|
| 206 | 38 | | private void OnDisable() { lastPlayedAnimation = AnimationStatus.Hide; } |
| | 39 | |
|
| 140 | 40 | | private void AppMode_OnChange(AppMode currentMode, AppMode previousMode) { SetInteractable(compatibleModes.Contains( |
| | 41 | |
|
| | 42 | | internal void PlayAnimation(AnimationStatus newStatus) |
| | 43 | | { |
| | 44 | | switch (newStatus) |
| | 45 | | { |
| | 46 | | case AnimationStatus.Hide: |
| 0 | 47 | | buttonAnimator.SetTrigger("Hide"); |
| 0 | 48 | | break; |
| | 49 | | case AnimationStatus.Visible: |
| 0 | 50 | | buttonAnimator.SetTrigger("Visible"); |
| 0 | 51 | | break; |
| | 52 | | case AnimationStatus.In: |
| 0 | 53 | | buttonAnimator.SetTrigger("In"); |
| 0 | 54 | | break; |
| | 55 | | case AnimationStatus.Out: |
| 11 | 56 | | buttonAnimator.SetTrigger("Out"); |
| | 57 | | break; |
| | 58 | | } |
| | 59 | |
|
| 11 | 60 | | lastPlayedAnimation = newStatus; |
| 11 | 61 | | } |
| | 62 | |
|
| | 63 | | internal float GetAnimationLenght() |
| | 64 | | { |
| 0 | 65 | | if (buttonAnimator.GetCurrentAnimatorClipInfoCount(0) == 0 || |
| | 66 | | buttonAnimator.GetCurrentAnimatorClipInfo(0).Length == 0) |
| 0 | 67 | | return 0f; |
| | 68 | |
|
| 0 | 69 | | return buttonAnimator.GetCurrentAnimatorClipInfo(0)[0].clip.length; |
| | 70 | | } |
| | 71 | |
|
| | 72 | | private void SetInteractable(bool isInteractable) |
| | 73 | | { |
| 70 | 74 | | mainButton.interactable = isInteractable; |
| | 75 | |
|
| 70 | 76 | | if (buttonText != null) |
| 70 | 77 | | buttonText.color = isInteractable ? originalTextColor : notInteractableColor; |
| 70 | 78 | | } |
| | 79 | | } |