< 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:36
Uncovered lines:13
Coverable lines:49
Total lines:110
Line coverage:73.4% (36 of 49)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Init(...)0%220100%
OnSelect()0%2.032080%
OnUnselect()0%110100%
OnMovingPlatformStart(...)0%6200%
OnMovingPlatformRotate(...)0%6200%
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;
 163979        protected Vector3NullableVariable characterForward => CommonScriptableObjects.characterForward;
 10
 11        private CinemachinePOV pov;
 12
 13        public override void Init(UnityEngine.Camera cameraTransform)
 14        {
 12515            base.Init(cameraTransform);
 16
 12517            if (defaultVirtualCamera is CinemachineVirtualCamera vcamera)
 12518                pov = vcamera.GetCinemachineComponent<CinemachinePOV>();
 12519        }
 20
 21        public override void OnSelect()
 22        {
 14623            base.OnSelect();
 14624            CommonScriptableObjects.playerIsOnMovingPlatform.OnChange += OnMovingPlatformStart;
 14625            if (CommonScriptableObjects.playerIsOnMovingPlatform.Get())
 026                OnMovingPlatformStart(true, true);
 14627        }
 28
 29        public override void OnUnselect()
 30        {
 14631            base.OnUnselect();
 14632            CommonScriptableObjects.playerIsOnMovingPlatform.OnChange -= OnMovingPlatformStart;
 14633            CommonScriptableObjects.movingPlatformRotationDelta.OnChange -= OnMovingPlatformRotate;
 14634        }
 35        private void OnMovingPlatformStart(bool current, bool previous)
 36        {
 037            if (current)
 38            {
 039                CommonScriptableObjects.movingPlatformRotationDelta.OnChange += OnMovingPlatformRotate;
 040            }
 41            else
 42            {
 043                CommonScriptableObjects.movingPlatformRotationDelta.OnChange -= OnMovingPlatformRotate;
 44            }
 045        }
 46        private void OnMovingPlatformRotate(Quaternion current, Quaternion previous)
 47        {
 048            Vector3 diff = current.eulerAngles;
 049            if (pov != null)
 50            {
 051                pov.m_HorizontalAxis.Value += diff.y;
 052                pov.m_VerticalAxis.Value += diff.x;
 53            }
 054        }
 55
 56        public override void OnUpdate()
 57        {
 1639758            var xzPlaneForward = Vector3.Scale(cameraTransform.forward, new Vector3(1, 0, 1));
 1639759            characterForward.Set(xzPlaneForward);
 1639760        }
 61
 62        public override Vector3 OnGetRotation()
 63        {
 1264            if (pov != null)
 1265                return new Vector3(pov.m_VerticalAxis.Value, pov.m_HorizontalAxis.Value, 0);
 66
 067            return Vector3.zero;
 68        }
 69
 70        public override void OnSetRotation(CameraController.SetRotationPayload payload)
 71        {
 3972            var eulerDir = Vector3.zero;
 73
 3974            if (payload.cameraTarget.HasValue)
 75            {
 3476                var newPos = new Vector3(payload.x, payload.y, payload.z);
 3477                var cameraTarget = payload.cameraTarget.GetValueOrDefault();
 3478                var dirToLook = (cameraTarget - newPos);
 3479                eulerDir = Quaternion.LookRotation(dirToLook).eulerAngles;
 80            }
 81
 3982            if (pov != null)
 83            {
 3984                pov.m_HorizontalAxis.Value = eulerDir.y;
 3985                pov.m_VerticalAxis.Value = eulerDir.x;
 86            }
 3987        }
 88
 89        public override void OnBlock(bool blocked)
 90        {
 1291            base.OnBlock(blocked);
 92
 1293            if (pov != null)
 94            {
 1295                if (blocked)
 96                {
 97                    // Before block the virtual camera, we make the main camera point to the same point as the virtual o
 698                    defaultVirtualCamera.transform.rotation = Quaternion.Euler(pov.m_VerticalAxis.Value, pov.m_Horizonta
 99                }
 100
 12101                pov.enabled = !blocked;
 102
 103                // NOTE(Santi): After modify the 'CinemachinePOV.enabled' parameter, the only (and not very elegant) way
 104                //              offers to force the update is deactivating and re-activating the virtual camera.
 12105                defaultVirtualCamera.enabled = false;
 12106                defaultVirtualCamera.enabled = true;
 107            }
 12108        }
 109    }
 110}