< 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
 59714        if (cameraPosition != null)
 15        {
 59716            transform.position = cameraPosition.position;
 17        }
 18
 59719        initialParent = transform.parent;
 20
 59721        firstPersonParent = cameraController.GetCamera().transform;
 22
 23        // Listen to changes on the camera mode
 59724        CommonScriptableObjects.cameraMode.OnChange += OnCameraModeChange;
 25
 26        // Trigger the initial camera set
 59727        OnCameraModeChange(CommonScriptableObjects.cameraMode, CommonScriptableObjects.cameraMode);
 28
 29        //There is no blend in the first set so we parent to the correct initial transform
 59730        SetNextParent();
 59731    }
 32
 30433    private void UpdateForward(Vector3 newForward, Vector3 prev) { transform.forward = newForward; }
 34
 35    private void OnDestroy()
 36    {
 59737        CommonScriptableObjects.cameraMode.OnChange -= OnCameraModeChange;
 59738        CommonScriptableObjects.cameraForward.OnChange -= UpdateForward;
 59739    }
 40
 41    private void OnCameraModeChange(CameraMode.ModeId newMode, CameraMode.ModeId prev)
 42    {
 59943        CommonScriptableObjects.cameraForward.OnChange -= UpdateForward;
 44
 59945        if (newMode == CameraMode.ModeId.FirstPerson)
 46        {
 50147            CommonScriptableObjects.cameraForward.OnChange += UpdateForward;
 50148            nextParent = firstPersonParent;
 49
 50150            if (cameraController != null)
 50151                cameraController.onCameraBlendFinished += SetNextParent;
 50152        }
 53        else
 54        {
 9855            if (newMode == CameraMode.ModeId.ThirdPerson)
 9856                transform.forward = initialParent.forward;
 57
 9858            nextParent = initialParent;
 59
 9860            if (cameraController != null)
 9861                cameraController.onCameraBlendStarted += SetNextParent;
 62        }
 9863    }
 64
 65    private void SetNextParent()
 66    {
 59867        if (cameraController != null)
 68        {
 59869            cameraController.onCameraBlendFinished -= SetNextParent;
 59870            cameraController.onCameraBlendStarted -= SetNextParent;
 71        }
 72
 59873        transform.SetParent(nextParent);
 59874    }
 75}