< 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
 59614        if (cameraPosition != null)
 15        {
 59616            transform.position = cameraPosition.position;
 17        }
 18
 59619        initialParent = transform.parent;
 20
 59621        firstPersonParent = cameraController.GetCamera().transform;
 22
 23        // Listen to changes on the camera mode
 59624        CommonScriptableObjects.cameraMode.OnChange += OnCameraModeChange;
 25
 26        // Trigger the initial camera set
 59627        OnCameraModeChange(CommonScriptableObjects.cameraMode, CommonScriptableObjects.cameraMode);
 28
 29        //There is no blend in the first set so we parent to the correct initial transform
 59630        SetNextParent();
 59631    }
 32
 30433    private void UpdateForward(Vector3 newForward, Vector3 prev) { transform.forward = newForward; }
 34
 35    private void OnDestroy()
 36    {
 59637        CommonScriptableObjects.cameraMode.OnChange -= OnCameraModeChange;
 59638        CommonScriptableObjects.cameraForward.OnChange -= UpdateForward;
 59639    }
 40
 41    private void OnCameraModeChange(CameraMode.ModeId newMode, CameraMode.ModeId prev)
 42    {
 59843        CommonScriptableObjects.cameraForward.OnChange -= UpdateForward;
 44
 59845        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        {
 9755            if (newMode == CameraMode.ModeId.ThirdPerson)
 9756                transform.forward = initialParent.forward;
 57
 9758            nextParent = initialParent;
 59
 9760            if (cameraController != null)
 9761                cameraController.onCameraBlendStarted += SetNextParent;
 62        }
 9763    }
 64
 65    private void SetNextParent()
 66    {
 59767        if (cameraController != null)
 68        {
 59769            cameraController.onCameraBlendFinished -= SetNextParent;
 59770            cameraController.onCameraBlendStarted -= SetNextParent;
 71        }
 72
 59773        transform.SetParent(nextParent);
 59774    }
 75}