< Summary

Class:VoiceChatButton
Assembly:VoiceChatButton
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/TaskbarHUD/VoiceChatButton/VoiceChatButton.cs
Covered lines:5
Uncovered lines:31
Coverable lines:36
Total lines:78
Line coverage:13.8% (5 of 36)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
VoiceChatButton()0%110100%
VoiceChatButton()0%110100%
OnPointerDown(...)0%2100%
OnPointerUp(...)0%2100%
SetOnRecording(...)0%6200%
SetEnabledByScene(...)0%30500%
OnVoiceChatInput(...)0%6200%
ShowDisabledTooltip()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/TaskbarHUD/VoiceChatButton/VoiceChatButton.cs

#LineLine coverage
 1using System;
 2using UnityEngine;
 3using UnityEngine.EventSystems;
 4
 5public class VoiceChatButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
 6{
 7    [SerializeField] InputAction_Hold voiceChatAction;
 8    [SerializeField] Animator buttonAnimator;
 9    [SerializeField] private Animator disabledTooltipAnimator;
 10
 111    private static readonly int talkingAnimation = Animator.StringToHash("Talking");
 112    private static readonly int disabledAnimation = Animator.StringToHash("Disabled");
 113    private static readonly int showDisabledTooltipAnimation = Animator.StringToHash("ShowDisabledTooltip");
 114    private static readonly int hideDisabledTooltipAnimation = Animator.StringToHash("HideDisabledTooltip");
 15
 16    private bool isRecording = false;
 517    private bool isEnabledByScene = true;
 18
 19    public void OnPointerDown(PointerEventData eventData) {
 020        Debug.Log("VOICECHATDEBUG: Pointer down");
 021        voiceChatAction.RaiseOnStarted();
 022    }
 23
 24    public void OnPointerUp(PointerEventData eventData)
 25    {
 026        Debug.Log("VOICECHATDEBUG: Pointer up");
 027        voiceChatAction.RaiseOnFinished();
 028    }
 29
 30    public void SetOnRecording(bool recording)
 31    {
 032        isRecording = recording;
 33
 034        if (!gameObject.activeInHierarchy)
 035            return;
 36
 037        buttonAnimator.SetBool(talkingAnimation, recording);
 038    }
 39
 40    public void SetEnabledByScene(bool enabledByScene)
 41    {
 042        bool hasChangedToDisable = !enabledByScene && isEnabledByScene;
 043        if (hasChangedToDisable)
 44        {
 045            if (isRecording)
 46            {
 047                ShowDisabledTooltip();
 48            }
 049            voiceChatAction.OnStarted -= OnVoiceChatInput;
 050            voiceChatAction.OnStarted += OnVoiceChatInput;
 051        }
 52        else
 53        {
 054            voiceChatAction.OnStarted -= OnVoiceChatInput;
 055            disabledTooltipAnimator.SetTrigger(hideDisabledTooltipAnimation);
 56        }
 57
 058        isEnabledByScene = enabledByScene;
 059        buttonAnimator.SetBool(disabledAnimation, !isEnabledByScene);
 060    }
 61
 62    private void OnVoiceChatInput(DCLAction_Hold action)
 63    {
 064        if (!isEnabledByScene)
 65        {
 066            ShowDisabledTooltip();
 67        }
 068    }
 69
 70    private void ShowDisabledTooltip()
 71    {
 072        if (disabledTooltipAnimator is null)
 073            return;
 74
 075        disabledTooltipAnimator.SetTrigger(hideDisabledTooltipAnimation);
 076        disabledTooltipAnimator.SetTrigger(showDisabledTooltipAnimation);
 077    }
 78}