< Summary

Class:DCLFeatures.ScreencaptureCamera.CameraObject.ScreencaptureCameraRotation
Assembly:ScreencaptureCamera
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/ScreencaptureCamera/CameraObject/Scripts/ScreencaptureCameraRotation.cs
Covered lines:0
Uncovered lines:31
Coverable lines:31
Total lines:80
Line coverage:0% (0 of 31)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:7
Method coverage:0% (0 of 7)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ScreencaptureCameraRotation(...)0%12300%
Rotate(...)0%6200%
Activate()0%6200%
Deactivate()0%2100%
EnableRotation(...)0%2100%
DisableRotation(...)0%2100%
SwitchRotation(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/ScreencaptureCamera/CameraObject/Scripts/ScreencaptureCameraRotation.cs

#LineLine coverage
 1using Cinemachine.Utility;
 2using DCL;
 3using DCL.Camera;
 4using DCL.Helpers;
 5using UnityEngine;
 6
 7namespace DCLFeatures.ScreencaptureCamera.CameraObject
 8{
 9    public class ScreencaptureCameraRotation
 10    {
 11        private const DCLAction_Hold DUMMY_ACTION = new ();
 12
 13        private readonly RotationInputSchema input;
 14        private readonly InputSpikeFixer[] inputSpikeFixer;
 15
 16        private bool mouseControlIsEnabled;
 17
 18        private Vector3 axis;
 19        private Vector3 axisTarget;
 20
 021        public ScreencaptureCameraRotation(RotationInputSchema inputSchema)
 22        {
 023            input = inputSchema;
 24
 025            inputSpikeFixer = new[]
 26            {
 027                new InputSpikeFixer(() => Utils.IsCursorLocked ? CursorLockMode.Locked : CursorLockMode.None),
 028                new InputSpikeFixer(() => Utils.IsCursorLocked ? CursorLockMode.Locked : CursorLockMode.None),
 29            };
 030        }
 31
 32        public void Rotate(Transform target, float deltaTime, float rotationSpeed, float dampTime, float maxRotationPerF
 33        {
 034            if (!mouseControlIsEnabled) return;
 35
 036            Vector3 currentAngles = target.eulerAngles;
 37
 038            axisTarget[0] = input.CameraXAxis.GetValue();
 039            axisTarget[1] = input.CameraYAxis.GetValue();
 040            axis += Damper.Damp(axisTarget - axis, dampTime, deltaTime);
 41
 042            currentAngles.y += Mathf.Clamp(inputSpikeFixer[0].GetValue(axis[0]) * rotationSpeed * deltaTime, -maxRotatio
 043            currentAngles.x -= Mathf.Clamp(inputSpikeFixer[1].GetValue(axis[1]) * rotationSpeed * deltaTime, -maxRotatio
 44
 045            target.rotation = Quaternion.Euler(currentAngles);
 046        }
 47
 48        public void Activate()
 49        {
 050            if (Utils.IsCursorLocked)
 051                EnableRotation(DUMMY_ACTION);
 52
 053            input.MouseFirstClick.OnStarted += EnableRotation;
 054            input.MouseFirstClick.OnFinished += DisableRotation;
 055        }
 56
 57        public void Deactivate()
 58        {
 059            DisableRotation(DUMMY_ACTION);
 60
 061            input.MouseFirstClick.OnStarted -= EnableRotation;
 062            input.MouseFirstClick.OnFinished -= DisableRotation;
 063        }
 64
 65        private void EnableRotation(DCLAction_Hold _) =>
 066            SwitchRotation(isEnabled: true);
 67
 68        private void DisableRotation(DCLAction_Hold _)
 69        {
 070            SwitchRotation(isEnabled: false);
 071            Utils.UnlockCursor();
 072        }
 73
 74        private void SwitchRotation(bool isEnabled)
 75        {
 076            DataStore.i.camera.panning.Set(false);
 077            mouseControlIsEnabled = isEnabled;
 078        }
 79    }
 80}