< 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:8
Uncovered lines:14
Coverable lines:22
Total lines:65
Line coverage:36.3% (8 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%2.862040%
UpdateDamp(...)0%30500%
UpdateAfterTeleportDamp()0%6200%

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
 59726        public CameraDampOnGroundType (Settings settings, FollowWithDamping followWithDamping)
 27        {
 59728            this.settings = settings;
 59729            this.followWithDamping = followWithDamping;
 59730            DataStore.i.player.lastTeleportPosition.OnChange += OnTeleport;
 59731        }
 7832        private void OnTeleport(Vector3 current, Vector3 previous) { zeroDampTime = AFTER_TELEPORT_DAMP_TIME_MS; }
 33
 34        public void Update(bool hitGround, RaycastHit hitInfo)
 35        {
 219836            if ( !settings.enabled )
 219837                return;
 38
 039            UpdateDamp(hitGround, hitInfo);
 040            UpdateAfterTeleportDamp();
 041        }
 42        private void UpdateDamp(bool hitGround, RaycastHit hitInfo)
 43        {
 044            bool isOnMovingPlatform = DCLCharacterController.i.isOnMovingPlatform;
 45
 046            if ( hitGround )
 47            {
 048                if ( hitInfo.distance < settings.groundCheckThreshold )
 049                    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        {
 058            if (zeroDampTime > 0)
 59            {
 060                followWithDamping.damping.y = 0;
 061                zeroDampTime -= Time.unscaledDeltaTime;
 62            }
 063        }
 64    }
 65}