| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.EventSystems; |
| | 4 | |
|
| | 5 | | public class VoiceChatButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler |
| | 6 | | { |
| | 7 | | [SerializeField] InputAction_Hold voiceChatAction; |
| | 8 | | [SerializeField] Animator buttonAnimator; |
| | 9 | | [SerializeField] private Animator disabledTooltipAnimator; |
| | 10 | |
|
| 1 | 11 | | private static readonly int talkingAnimation = Animator.StringToHash("Talking"); |
| 1 | 12 | | private static readonly int disabledAnimation = Animator.StringToHash("Disabled"); |
| 1 | 13 | | private static readonly int showDisabledTooltipAnimation = Animator.StringToHash("ShowDisabledTooltip"); |
| 1 | 14 | | private static readonly int hideDisabledTooltipAnimation = Animator.StringToHash("HideDisabledTooltip"); |
| | 15 | |
|
| | 16 | | private bool isRecording = false; |
| 5 | 17 | | private bool isEnabledByScene = true; |
| | 18 | |
|
| | 19 | | public void OnPointerDown(PointerEventData eventData) { |
| 0 | 20 | | Debug.Log("VOICECHATDEBUG: Pointer down"); |
| 0 | 21 | | voiceChatAction.RaiseOnStarted(); |
| 0 | 22 | | } |
| | 23 | |
|
| | 24 | | public void OnPointerUp(PointerEventData eventData) |
| | 25 | | { |
| 0 | 26 | | Debug.Log("VOICECHATDEBUG: Pointer up"); |
| 0 | 27 | | voiceChatAction.RaiseOnFinished(); |
| 0 | 28 | | } |
| | 29 | |
|
| | 30 | | public void SetOnRecording(bool recording) |
| | 31 | | { |
| 0 | 32 | | isRecording = recording; |
| | 33 | |
|
| 0 | 34 | | if (!gameObject.activeInHierarchy) |
| 0 | 35 | | return; |
| | 36 | |
|
| 0 | 37 | | buttonAnimator.SetBool(talkingAnimation, recording); |
| 0 | 38 | | } |
| | 39 | |
|
| | 40 | | public void SetEnabledByScene(bool enabledByScene) |
| | 41 | | { |
| 0 | 42 | | bool hasChangedToDisable = !enabledByScene && isEnabledByScene; |
| 0 | 43 | | if (hasChangedToDisable) |
| | 44 | | { |
| 0 | 45 | | if (isRecording) |
| | 46 | | { |
| 0 | 47 | | ShowDisabledTooltip(); |
| | 48 | | } |
| 0 | 49 | | voiceChatAction.OnStarted -= OnVoiceChatInput; |
| 0 | 50 | | voiceChatAction.OnStarted += OnVoiceChatInput; |
| 0 | 51 | | } |
| | 52 | | else |
| | 53 | | { |
| 0 | 54 | | voiceChatAction.OnStarted -= OnVoiceChatInput; |
| 0 | 55 | | disabledTooltipAnimator.SetTrigger(hideDisabledTooltipAnimation); |
| | 56 | | } |
| | 57 | |
|
| 0 | 58 | | isEnabledByScene = enabledByScene; |
| 0 | 59 | | buttonAnimator.SetBool(disabledAnimation, !isEnabledByScene); |
| 0 | 60 | | } |
| | 61 | |
|
| | 62 | | private void OnVoiceChatInput(DCLAction_Hold action) |
| | 63 | | { |
| 0 | 64 | | if (!isEnabledByScene) |
| | 65 | | { |
| 0 | 66 | | ShowDisabledTooltip(); |
| | 67 | | } |
| 0 | 68 | | } |
| | 69 | |
|
| | 70 | | private void ShowDisabledTooltip() |
| | 71 | | { |
| 0 | 72 | | if (disabledTooltipAnimator is null) |
| 0 | 73 | | return; |
| | 74 | |
|
| 0 | 75 | | disabledTooltipAnimator.SetTrigger(hideDisabledTooltipAnimation); |
| 0 | 76 | | disabledTooltipAnimator.SetTrigger(showDisabledTooltipAnimation); |
| 0 | 77 | | } |
| | 78 | | } |