< Summary

Class:DCL.Camera.CameraDampOnGroundType
Assembly:Camera
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Camera/CameraDampOnGroundType.cs
Covered lines:17
Uncovered lines:5
Coverable lines:22
Total lines:65
Line coverage:77.2% (17 of 22)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Settings()0%2100%
CameraDampOnGroundType(...)0%110100%
OnTeleport(...)0%110100%
Update(...)0%220100%
UpdateDamp(...)0%5.935066.67%
UpdateAfterTeleportDamp()0%2.52050%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Camera/CameraDampOnGroundType.cs

#LineLine coverage
 1using Cinemachine;
 2using UnityEngine;
 3
 4namespace DCL.Camera
 5{
 6    public class CameraDampOnGroundType
 7    {
 8        private const float AFTER_TELEPORT_DAMP_TIME_MS = 50f;
 9
 10        [System.Serializable]
 11        public class Settings
 12        {
 013            public bool enabled = true;
 14            public float dampingOnAir;
 15            public float dampingOnGround;
 16            public float dampingOnMovingPlatform;
 17
 18            [Tooltip("Min raycast ground distance to be considered airborne")]
 19            public float groundCheckThreshold;
 20        }
 21
 22        private FollowWithDamping followWithDamping;
 23        public Settings settings;
 24        private float zeroDampTime;
 25
 12426        public CameraDampOnGroundType (Settings settings, FollowWithDamping followWithDamping)
 27        {
 12428            this.settings = settings;
 12429            this.followWithDamping = followWithDamping;
 12430            DataStore.i.player.lastTeleportPosition.OnChange += OnTeleport;
 12431        }
 1832        private void OnTeleport(Vector3 current, Vector3 previous) { zeroDampTime = AFTER_TELEPORT_DAMP_TIME_MS; }
 33
 34        public void Update(bool hitGround, RaycastHit hitInfo)
 35        {
 855336            if ( !settings.enabled )
 651337                return;
 38
 204039            UpdateDamp(hitGround, hitInfo);
 204040            UpdateAfterTeleportDamp();
 204041        }
 42        private void UpdateDamp(bool hitGround, RaycastHit hitInfo)
 43        {
 204044            bool isOnMovingPlatform = DCLCharacterController.i.isOnMovingPlatform;
 45
 204046            if ( hitGround )
 47            {
 204048                if ( hitInfo.distance < settings.groundCheckThreshold )
 204049                    followWithDamping.damping.y = isOnMovingPlatform ? settings.dampingOnMovingPlatform : settings.dampi
 50                else
 051                    followWithDamping.damping.y = settings.dampingOnAir;
 52            }
 053        }
 54
 55        // This avoids the "Camera clips through stuff" after teleporting to different heights
 56        private void UpdateAfterTeleportDamp()
 57        {
 204058            if (zeroDampTime > 0)
 59            {
 060                followWithDamping.damping.y = 0;
 061                zeroDampTime -= Time.unscaledDeltaTime;
 62            }
 204063        }
 64    }
 65}