< 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:27
Coverable lines:32
Total lines:71
Line coverage:15.6% (5 of 32)
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
 019    public void OnPointerDown(PointerEventData eventData) { voiceChatAction.RaiseOnStarted(); }
 20
 021    public void OnPointerUp(PointerEventData eventData) { voiceChatAction.RaiseOnFinished(); }
 22
 23    public void SetOnRecording(bool recording)
 24    {
 025        isRecording = recording;
 26
 027        if (!gameObject.activeInHierarchy)
 028            return;
 29
 030        buttonAnimator.SetBool(talkingAnimation, recording);
 031    }
 32
 33    public void SetEnabledByScene(bool enabledByScene)
 34    {
 035        bool hasChangedToDisable = !enabledByScene && isEnabledByScene;
 036        if (hasChangedToDisable)
 37        {
 038            if (isRecording)
 39            {
 040                ShowDisabledTooltip();
 41            }
 042            voiceChatAction.OnStarted -= OnVoiceChatInput;
 043            voiceChatAction.OnStarted += OnVoiceChatInput;
 044        }
 45        else
 46        {
 047            voiceChatAction.OnStarted -= OnVoiceChatInput;
 048            disabledTooltipAnimator.SetTrigger(hideDisabledTooltipAnimation);
 49        }
 50
 051        isEnabledByScene = enabledByScene;
 052        buttonAnimator.SetBool(disabledAnimation, !isEnabledByScene);
 053    }
 54
 55    private void OnVoiceChatInput(DCLAction_Hold action)
 56    {
 057        if (!isEnabledByScene)
 58        {
 059            ShowDisabledTooltip();
 60        }
 061    }
 62
 63    private void ShowDisabledTooltip()
 64    {
 065        if (disabledTooltipAnimator is null)
 066            return;
 67
 068        disabledTooltipAnimator.SetTrigger(hideDisabledTooltipAnimation);
 069        disabledTooltipAnimator.SetTrigger(showDisabledTooltipAnimation);
 070    }
 71}