< Summary

Class:DCL.AvatarVisibility
Assembly:AvatarShape
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Avatar/AvatarVisibility.cs
Covered lines:14
Uncovered lines:1
Coverable lines:15
Total lines:54
Line coverage:93.3% (14 of 15)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AvatarVisibility()0%110100%
SetVisibility(...)0%6.046090%
SetVisibilityForGameObjects(...)0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Avatar/AvatarVisibility.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using UnityEngine;
 3
 4namespace DCL
 5{
 6    /// <summary>
 7    /// This class handles the avatar's visibility. Different callers will determine whether they want the avatar to be 
 8    /// The avatar will be rendered only when all callers want the avatar to be visible. It only takes one caller to mak
 9    /// </summary>
 10    public class AvatarVisibility : MonoBehaviour
 11    {
 12
 13        [Tooltip("Game objects that should be hidden/shown")]
 14        public GameObject[] gameObjectsToToggle;
 15        // A list of all the callers that want to hide the avatar
 103616        private readonly HashSet<string> callsToHide = new HashSet<string>();
 17
 18        public event System.Action<bool> OnSetVisibility;
 19
 20        public void SetVisibility(string callerId, bool visibility)
 21        {
 422            if (visibility)
 23            {
 224                bool removed = callsToHide.Remove(callerId);
 225                if (removed && callsToHide.Count == 0)
 26                {
 27                    // Show
 128                    SetVisibilityForGameObjects(true);
 29                }
 130            }
 31            else
 32            {
 233                bool added = callsToHide.Add(callerId);
 234                if (added)
 35                {
 36                    // Hide
 237                    SetVisibilityForGameObjects(false);
 38                }
 39            }
 440            OnSetVisibility?.Invoke(visibility);
 041        }
 42
 43        internal void SetVisibilityForGameObjects(bool value)
 44        {
 2445            foreach (GameObject gameObject in gameObjectsToToggle)
 46            {
 747                if (gameObject == null)
 48                    continue;
 49
 550                gameObject.SetActive(value);
 51            }
 552        }
 53    }
 54}