< 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:28
Uncovered lines:2
Coverable lines:30
Total lines:75
Line coverage:93.3% (28 of 30)
Covered branches:0
Total branches:0

Metrics

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

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;
 103829        protected Vector3NullableVariable characterForward => CommonScriptableObjects.characterForward;
 10
 11        private CinemachinePOV pov;
 12
 13        public override void Init(UnityEngine.Camera cameraTransform)
 14        {
 12415            base.Init(cameraTransform);
 16
 12417            if (defaultVirtualCamera is CinemachineVirtualCamera vcamera)
 12418                pov = vcamera.GetCinemachineComponent<CinemachinePOV>();
 12419        }
 20
 21        public override void OnUpdate()
 22        {
 1038223            var xzPlaneForward = Vector3.Scale(cameraTransform.forward, new Vector3(1, 0, 1));
 1038224            characterForward.Set(xzPlaneForward);
 1038225        }
 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        {
 4037            var eulerDir = Vector3.zero;
 38
 4039            if (payload.cameraTarget.HasValue)
 40            {
 3441                var newPos = new Vector3(payload.x, payload.y, payload.z);
 3442                var cameraTarget = payload.cameraTarget.GetValueOrDefault();
 3443                var dirToLook = (cameraTarget - newPos);
 3444                eulerDir = Quaternion.LookRotation(dirToLook).eulerAngles;
 45            }
 46
 4047            if (pov != null)
 48            {
 4049                pov.m_HorizontalAxis.Value = eulerDir.y;
 4050                pov.m_VerticalAxis.Value = eulerDir.x;
 51            }
 4052        }
 53
 54        public override void OnBlock(bool blocked)
 55        {
 1256            base.OnBlock(blocked);
 57
 1258            if (pov != null)
 59            {
 1260                if (blocked)
 61                {
 62                    // Before block the virtual camera, we make the main camera point to the same point as the virtual o
 663                    defaultVirtualCamera.transform.rotation = Quaternion.Euler(pov.m_VerticalAxis.Value, pov.m_Horizonta
 64                }
 65
 1266                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.
 1270                defaultVirtualCamera.enabled = false;
 1271                defaultVirtualCamera.enabled = true;
 72            }
 1273        }
 74    }
 75}