< Summary

Class:FirstPersonCameraEntityReference
Assembly:FirstPersonCameraEntity
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/CharacterController/FirstPersonCameraReference/FirstPersonCameraEntityReference.cs
Covered lines:30
Uncovered lines:0
Coverable lines:30
Total lines:75
Line coverage:100% (30 of 30)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%220100%
UpdateForward(...)0%110100%
OnDestroy()0%110100%
OnCameraModeChange(...)0%550100%
SetNextParent()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/CharacterController/FirstPersonCameraReference/FirstPersonCameraEntityReference.cs

#LineLine coverage
 1using DCL.Camera;
 2using UnityEngine;
 3
 4public class FirstPersonCameraEntityReference : MonoBehaviour
 5{
 6    public CameraController cameraController;
 7    public Transform cameraPosition;
 8
 9    private Transform nextParent, firstPersonParent, initialParent;
 10
 11    private void Awake()
 12    {
 13        // Assign the camera position to the game object
 60914        if (cameraPosition != null)
 15        {
 60916            transform.position = cameraPosition.position;
 17        }
 18
 60919        initialParent = transform.parent;
 20
 60921        firstPersonParent = cameraController.GetCamera().transform;
 22
 23        // Listen to changes on the camera mode
 60924        CommonScriptableObjects.cameraMode.OnChange += OnCameraModeChange;
 25
 26        // Trigger the initial camera set
 60927        OnCameraModeChange(CommonScriptableObjects.cameraMode, CommonScriptableObjects.cameraMode);
 28
 29        //There is no blend in the first set so we parent to the correct initial transform
 60930        SetNextParent();
 60931    }
 32
 26233    private void UpdateForward(Vector3 newForward, Vector3 prev) { transform.forward = newForward; }
 34
 35    private void OnDestroy()
 36    {
 60937        CommonScriptableObjects.cameraMode.OnChange -= OnCameraModeChange;
 60938        CommonScriptableObjects.cameraForward.OnChange -= UpdateForward;
 60939    }
 40
 41    private void OnCameraModeChange(CameraMode.ModeId newMode, CameraMode.ModeId prev)
 42    {
 61143        CommonScriptableObjects.cameraForward.OnChange -= UpdateForward;
 44
 61145        if (newMode == CameraMode.ModeId.FirstPerson)
 46        {
 50647            CommonScriptableObjects.cameraForward.OnChange += UpdateForward;
 50648            nextParent = firstPersonParent;
 49
 50650            if (cameraController != null)
 50651                cameraController.onCameraBlendFinished += SetNextParent;
 50652        }
 53        else
 54        {
 10555            if (newMode == CameraMode.ModeId.ThirdPerson)
 10556                transform.forward = initialParent.forward;
 57
 10558            nextParent = initialParent;
 59
 10560            if (cameraController != null)
 10561                cameraController.onCameraBlendStarted += SetNextParent;
 62        }
 10563    }
 64
 65    private void SetNextParent()
 66    {
 61067        if (cameraController != null)
 68        {
 61069            cameraController.onCameraBlendFinished -= SetNextParent;
 61070            cameraController.onCameraBlendStarted -= SetNextParent;
 71        }
 72
 61073        transform.SetParent(nextParent);
 61074    }
 75}