< Summary

Class:FirstPersonCameraEntityReference
Assembly:FirstPersonCameraEntity
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/CharacterController/FirstPersonCameraReference/FirstPersonCameraEntityReference.cs
Covered lines:29
Uncovered lines:0
Coverable lines:29
Total lines:76
Line coverage:100% (29 of 29)
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 DCL.CameraTool;
 3using UnityEngine;
 4
 5public class FirstPersonCameraEntityReference : MonoBehaviour
 6{
 7    public CameraController cameraController;
 8    public Transform cameraPosition;
 9
 10    private Transform nextParent, firstPersonParent, initialParent;
 11
 12    private void Awake()
 13    {
 14        // Assign the camera position to the game object
 40515        if (cameraPosition != null)
 16        {
 40517            transform.position = cameraPosition.position;
 18        }
 19
 40520        initialParent = transform.parent;
 21
 40522        firstPersonParent = cameraController.GetCamera().transform;
 23
 24        // Listen to changes on the camera mode
 40525        CommonScriptableObjects.cameraMode.OnChange += OnCameraModeChange;
 26
 27        // Trigger the initial camera set
 40528        OnCameraModeChange(CommonScriptableObjects.cameraMode, CommonScriptableObjects.cameraMode);
 29
 30        //There is no blend in the first set so we parent to the correct initial transform
 40531        SetNextParent();
 40532    }
 33
 634    private void UpdateForward(Vector3 newForward, Vector3 prev) { transform.forward = newForward; }
 35
 36    private void OnDestroy()
 37    {
 40538        CommonScriptableObjects.cameraMode.OnChange -= OnCameraModeChange;
 40539        CommonScriptableObjects.cameraForward.OnChange -= UpdateForward;
 40540    }
 41
 42    private void OnCameraModeChange(CameraMode.ModeId newMode, CameraMode.ModeId prev)
 43    {
 41344        CommonScriptableObjects.cameraForward.OnChange -= UpdateForward;
 45
 41346        if (newMode == CameraMode.ModeId.FirstPerson)
 47        {
 1148            CommonScriptableObjects.cameraForward.OnChange += UpdateForward;
 1149            nextParent = firstPersonParent;
 50
 1151            if (cameraController != null)
 1152                cameraController.onCameraBlendFinished += SetNextParent;
 53        }
 54        else
 55        {
 40256            if (newMode == CameraMode.ModeId.ThirdPerson)
 40257                transform.forward = initialParent.forward;
 58
 40259            nextParent = initialParent;
 60
 40261            if (cameraController != null)
 40262                cameraController.onCameraBlendStarted += SetNextParent;
 63        }
 40264    }
 65
 66    private void SetNextParent()
 67    {
 40568        if (cameraController != null)
 69        {
 40570            cameraController.onCameraBlendFinished -= SetNextParent;
 40571            cameraController.onCameraBlendStarted -= SetNextParent;
 72        }
 73
 40574        transform.SetParent(nextParent);
 40575    }
 76}