< 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:20
Uncovered lines:10
Coverable lines:30
Total lines:75
Line coverage:66.6% (20 of 30)
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;
 68159        protected Vector3NullableVariable characterForward => CommonScriptableObjects.characterForward;
 10
 11        private CinemachinePOV pov;
 12
 13        public override void Initialize(UnityEngine.Camera cameraTransform)
 14        {
 61015            base.Initialize(cameraTransform);
 16
 61017            if (defaultVirtualCamera is CinemachineVirtualCamera vcamera)
 61018                pov = vcamera.GetCinemachineComponent<CinemachinePOV>();
 61019        }
 20
 21        public override void OnUpdate()
 22        {
 681523            var xzPlaneForward = Vector3.Scale(cameraTransform.forward, new Vector3(1, 0, 1));
 681524            characterForward.Set(xzPlaneForward);
 681525        }
 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 newPos = new Vector3(payload.x, payload.y, payload.z);
 642                var cameraTarget = payload.cameraTarget.GetValueOrDefault();
 643                var dirToLook = (cameraTarget - newPos);
 644                eulerDir = Quaternion.LookRotation(dirToLook).eulerAngles;
 45            }
 46
 647            if (pov != null)
 48            {
 649                pov.m_HorizontalAxis.Value = eulerDir.y;
 650                pov.m_VerticalAxis.Value = eulerDir.x;
 51            }
 652        }
 53
 54        public override void OnBlock(bool blocked)
 55        {
 056            base.OnBlock(blocked);
 57
 058            if (pov != null)
 59            {
 060                if (blocked)
 61                {
 62                    // Before block the virtual camera, we make the main camera point to the same point as the virtual o
 063                    defaultVirtualCamera.transform.rotation = Quaternion.Euler(pov.m_VerticalAxis.Value, pov.m_Horizonta
 64                }
 65
 066                pov.enabled = !blocked;
 67
 68                // NOTE(Santi): After modify the 'CinemachinePOV.enabled' parameter, the only (and not very elegant) way
 69                //              offers to force the update is deactivating and re-activating the virtual camera.
 070                defaultVirtualCamera.enabled = false;
 071                defaultVirtualCamera.enabled = true;
 72            }
 073        }
 74    }
 75}