< Summary

Class:DCL.Camera.CameraFreefall
Assembly:Camera
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Camera/CameraFreefall.cs
Covered lines:6
Uncovered lines:22
Coverable lines:28
Total lines:79
Line coverage:21.4% (6 of 28)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Settings()0%2100%
CameraFreefall(...)0%110100%
Update(...)0%56.09809.09%

File(s)

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

#LineLine coverage
 1using Cinemachine;
 2using UnityEngine;
 3
 4namespace DCL.Camera
 5{
 6    public class CameraFreefall
 7    {
 8        [System.Serializable]
 9        public class Settings
 10        {
 011            public bool enabled = true;
 12
 13            public CinemachineVirtualCamera freefallVirtualCamera;
 14
 15            public float fallDetectionDelay;
 16
 17            [Tooltip("Min raycast ground distance to be considered a fall")]
 18            public float fallGroundDistanceThreshold;
 19        }
 20
 21        public Settings settings;
 22        private CinemachineFreeLook defaultFreeLookCamera;
 23
 24        private Vector3 lastPosition;
 25        private float fallDetectionTimer;
 026        protected Vector3Variable characterPosition => CommonScriptableObjects.playerUnityPosition;
 27
 59728        public CameraFreefall (Settings settings, CinemachineFreeLook defaultFreeLookCamera)
 29        {
 59730            this.defaultFreeLookCamera = defaultFreeLookCamera;
 59731            this.settings = settings;
 59732        }
 33
 34        public void Update(bool hitGround, RaycastHit hitInfo)
 35        {
 219836            if ( !settings.enabled )
 219837                return;
 38
 039            bool useFallingCamera = false;
 40
 041            if ( hitGround )
 42            {
 043                useFallingCamera = hitInfo.distance > settings.fallGroundDistanceThreshold;
 044            }
 45            else
 46            {
 047                useFallingCamera = true;
 48            }
 49
 50
 051            Vector3 velocity = characterPosition - lastPosition;
 52
 053            if ( velocity.y < 0 )
 54            {
 055                fallDetectionTimer += Time.deltaTime;
 56
 057                if ( fallDetectionTimer < settings.fallDetectionDelay )
 058                    useFallingCamera = false;
 059            }
 60            else
 61            {
 062                fallDetectionTimer = 0;
 63            }
 64
 065            lastPosition = characterPosition;
 66
 067            if ( settings.freefallVirtualCamera.gameObject.activeSelf != useFallingCamera)
 068                settings.freefallVirtualCamera.gameObject.SetActive(useFallingCamera);
 69
 070            if ( useFallingCamera )
 71            {
 072                var orbitalTransposer = settings.freefallVirtualCamera.GetCinemachineComponent<CinemachineOrbitalTranspo
 73
 074                if ( orbitalTransposer != null )
 075                    orbitalTransposer.m_XAxis = defaultFreeLookCamera.m_XAxis;
 76            }
 077        }
 78    }
 79}