< Summary

Class:NotificationBadge
Assembly:NotificationBadge
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationBadge/NotificationBadge.cs
Covered lines:22
Uncovered lines:5
Coverable lines:27
Total lines:67
Line coverage:81.4% (22 of 27)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%110100%
Initialize()0%4.024088.89%
OnDestroy()0%4.054085.71%
NotificationVariable_OnChange(...)0%4.044086.67%

File(s)

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

#LineLine coverage
 1using System.Collections.Generic;
 2using UnityEngine;
 3
 4public class NotificationBadge : MonoBehaviour
 5{
 6    [Tooltip("The value shown on this badge is the sum of the notification variables")]
 7    [SerializeField] private List<FloatVariable> notificationVariables;
 8    [SerializeField] private TMPro.TextMeshProUGUI notificationText;
 9    [SerializeField] private GameObject notificationContainer;
 10
 011    public int finalValue { get; private set; }
 5212    private void Start() { Initialize(); }
 13
 14    public void Initialize()
 15    {
 2816        if (notificationVariables == null || notificationVariables.Count == 0)
 017            return;
 18
 12219        foreach (var notiVariable in notificationVariables)
 20        {
 3321            notiVariable.OnChange -= NotificationVariable_OnChange;
 3322            notiVariable.OnChange += NotificationVariable_OnChange;
 3323            NotificationVariable_OnChange(notiVariable.Get(), notiVariable.Get());
 24        }
 2825    }
 26
 27    private void OnDestroy()
 28    {
 2829        if (notificationVariables == null || notificationVariables.Count == 0)
 030            return;
 31
 12232        foreach (var notiVariable in notificationVariables)
 33        {
 3334            notiVariable.OnChange -= NotificationVariable_OnChange;
 35        }
 2836    }
 37
 38    private void NotificationVariable_OnChange(float current, float previous)
 39    {
 4940        int finalValue = 0;
 41
 23242        foreach (var notiVariable in notificationVariables)
 43        {
 6744            finalValue += (int)notiVariable.Get();
 45        }
 46
 4947        this.finalValue = finalValue;
 48
 4949        if (finalValue > 0)
 50        {
 2351            notificationContainer.SetActive(true);
 52
 2353            if (finalValue < 99)
 54            {
 2355                notificationText.text = finalValue.ToString();
 2356            }
 57            else
 58            {
 059                notificationText.text = "99+";
 60            }
 061        }
 62        else
 63        {
 2664            notificationContainer.SetActive(false);
 65        }
 2666    }
 67}