< Summary

Class:DCL.Camera.CameraStateFPS
Assembly:Camera
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Camera/CameraStateFPS.cs
Covered lines:21
Uncovered lines:10
Coverable lines:31
Total lines:78
Line coverage:67.7% (21 of 31)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize(...)0%220100%
OnUpdate()0%110100%
OnGetRotation()0%2.152066.67%
OnSetRotation(...)0%330100%
OnBlock(...)0%12300%

File(s)

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

#LineLine coverage
 1using Cinemachine;
 2using UnityEngine;
 3
 4namespace DCL.Camera
 5{
 6    public class CameraStateFPS : CameraStateBase
 7    {
 08        protected Vector3Variable cameraForward => CommonScriptableObjects.cameraForward;
 399        protected Vector3NullableVariable characterForward => CommonScriptableObjects.characterForward;
 10
 11        private CinemachinePOV pov;
 12
 13        public override void Initialize(UnityEngine.Camera cameraTransform)
 14        {
 40515            base.Initialize(cameraTransform);
 16
 40517            if (defaultVirtualCamera is CinemachineVirtualCamera vcamera)
 40518                pov = vcamera.GetCinemachineComponent<CinemachinePOV>();
 40519        }
 20
 21        public override void OnUpdate()
 22        {
 3923            var xzPlaneForward = Vector3.Scale(cameraTransform.forward, new Vector3(1, 0, 1));
 3924            characterForward.Set(xzPlaneForward);
 3925        }
 26
 27        public override Vector3 OnGetRotation()
 28        {
 1229            if (pov != null)
 1230                return new Vector3(pov.m_VerticalAxis.Value, pov.m_HorizontalAxis.Value, 0);
 31
 032            return Vector3.zero;
 33        }
 34
 35        public override void OnSetRotation(CameraController.SetRotationPayload payload)
 36        {
 637            var eulerDir = Vector3.zero;
 38
 639            if (payload.cameraTarget.HasValue)
 40            {
 641                var cameraTarget = payload.cameraTarget.GetValueOrDefault();
 42
 643                var horizontalAxisLookAt = payload.y - cameraTarget.y;
 644                var verticalAxisLookAt = new Vector3(cameraTarget.x - payload.x, 0, cameraTarget.z - payload.z);
 45
 646                eulerDir.y = Vector3.SignedAngle(Vector3.forward, verticalAxisLookAt, Vector3.up);
 647                eulerDir.x = Mathf.Atan2(horizontalAxisLookAt, verticalAxisLookAt.magnitude) * Mathf.Rad2Deg;
 48            }
 49
 650            if (pov != null)
 51            {
 652                pov.m_HorizontalAxis.Value = eulerDir.y;
 653                pov.m_VerticalAxis.Value = eulerDir.x;
 54            }
 655        }
 56
 57        public override void OnBlock(bool blocked)
 58        {
 059            base.OnBlock(blocked);
 60
 061            if (pov != null)
 62            {
 063                if (blocked)
 64                {
 65                    // Before block the virtual camera, we make the main camera point to the same point as the virtual o
 066                    defaultVirtualCamera.transform.rotation = Quaternion.Euler(pov.m_VerticalAxis.Value, pov.m_Horizonta
 67                }
 68
 069                pov.enabled = !blocked;
 70
 71                // NOTE(Santi): After modify the 'CinemachinePOV.enabled' parameter, the only (and not very elegant) way
 72                //              offers to force the update is deactivating and re-activating the virtual camera.
 073                defaultVirtualCamera.enabled = false;
 074                defaultVirtualCamera.enabled = true;
 75            }
 076        }
 77    }
 78}