< Summary

Class:DCL.AvatarLODController
Assembly:AvatarLODController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Avatar/AvatarLOD/AvatarLODController/AvatarLODController.cs
Covered lines:27
Uncovered lines:2
Coverable lines:29
Total lines:82
Line coverage:93.1% (27 of 29)
Covered branches:0
Total branches:0
Covered methods:12
Total methods:13
Method coverage:92.3% (12 of 13)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AvatarLODController(...)0%330100%
SetLOD0()0%110100%
SetLOD1()0%110100%
SetLOD2()0%110100%
SetLODLevel(...)0%440100%
SetInvisible()0%4.074083.33%
SetAnimationThrottling(...)0%330100%
SetNameVisible(...)0%440100%
UpdateImpostorTint(...)0%12300%
Dispose()0%110100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections;
 3using UnityEngine;
 4
 5namespace DCL
 6{
 7    //TODO Rename to IAvatar (not now to avoid conflicts)
 8    public interface IAvatarLODController : IDisposable
 9    {
 10        Player player { get; }
 11        void SetLOD0();
 12        void SetLOD1();
 13        void SetLOD2();
 14        public void SetAnimationThrottling(int framesBetweenUpdates);
 15        void SetInvisible();
 16        void UpdateImpostorTint(float distanceToMainPlayer);
 17        void SetNameVisible(bool visible);
 18
 19        bool IsInvisible { get; }
 20    }
 21
 22    public class AvatarLODController : IAvatarLODController
 23    {
 24        private const string VISIBILITY_CONSTRAIN = "behind_camera_or_out_of_limits";
 14825        public Player player { get; }
 26
 527        public bool IsInvisible { get; private set; }
 28
 2529        public AvatarLODController(Player player)
 30        {
 2531            this.player = player;
 2532            player?.avatar?.SetLODLevel(0);
 2233        }
 34
 35        public void SetLOD0() =>
 3036            SetLODLevel(0, setPointerColliderEnabled: true);
 37
 38        public void SetLOD1() =>
 239            SetLODLevel(1, setPointerColliderEnabled: true);
 40
 41        public void SetLOD2() =>
 242            SetLODLevel(2, setPointerColliderEnabled: false);
 43
 44        private void SetLODLevel(int level, bool setPointerColliderEnabled)
 45        {
 3446            if (player?.avatar == null)
 3047                return;
 48
 449            player.onPointerDownCollider.SetColliderEnabled(setPointerColliderEnabled);
 450            player.avatar.SetLODLevel(level);
 451            player.avatar.RemoveVisibilityConstrain(VISIBILITY_CONSTRAIN);
 52
 453            IsInvisible = false;
 454        }
 55
 56        public void SetInvisible()
 57        {
 158            if (player?.avatar == null)
 059                return;
 60
 161            player.avatar.AddVisibilityConstraint(VISIBILITY_CONSTRAIN);
 162            player.onPointerDownCollider.SetColliderEnabled(false);
 163            IsInvisible = true;
 164        }
 65
 66        public void SetAnimationThrottling(int framesBetweenUpdates) =>
 2467            player?.avatar?.SetAnimationThrottling(framesBetweenUpdates);
 68
 69        public void SetNameVisible(bool visible)
 70        {
 2471            if (visible)
 1072                player?.playerName.Show();
 73            else
 1474                player?.playerName.Hide();
 1475        }
 76
 77        public void UpdateImpostorTint(float distanceToMainPlayer) =>
 078            player?.avatar?.SetImpostorTint(AvatarRendererHelpers.CalculateImpostorTint(distanceToMainPlayer));
 79
 380        public void Dispose() { }
 81    }
 82}