< 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:76
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 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
 59115        if (cameraPosition != null)
 16        {
 59117            transform.position = cameraPosition.position;
 18        }
 19
 59120        initialParent = transform.parent;
 21
 59122        firstPersonParent = cameraController.GetCamera().transform;
 23
 24        // Listen to changes on the camera mode
 59125        CommonScriptableObjects.cameraMode.OnChange += OnCameraModeChange;
 26
 27        // Trigger the initial camera set
 59128        OnCameraModeChange(CommonScriptableObjects.cameraMode, CommonScriptableObjects.cameraMode);
 29
 30        //There is no blend in the first set so we parent to the correct initial transform
 59131        SetNextParent();
 59132    }
 33
 28634    private void UpdateForward(Vector3 newForward, Vector3 prev) { transform.forward = newForward; }
 35
 36    private void OnDestroy()
 37    {
 59138        CommonScriptableObjects.cameraMode.OnChange -= OnCameraModeChange;
 59139        CommonScriptableObjects.cameraForward.OnChange -= UpdateForward;
 59140    }
 41
 42    private void OnCameraModeChange(CameraMode.ModeId newMode, CameraMode.ModeId prev)
 43    {
 59344        CommonScriptableObjects.cameraForward.OnChange -= UpdateForward;
 45
 59346        if (newMode == CameraMode.ModeId.FirstPerson)
 47        {
 29148            CommonScriptableObjects.cameraForward.OnChange += UpdateForward;
 29149            nextParent = firstPersonParent;
 50
 29151            if (cameraController != null)
 29152                cameraController.onCameraBlendFinished += SetNextParent;
 29153        }
 54        else
 55        {
 30256            if (newMode == CameraMode.ModeId.ThirdPerson)
 30257                transform.forward = initialParent.forward;
 58
 30259            nextParent = initialParent;
 60
 30261            if (cameraController != null)
 30262                cameraController.onCameraBlendStarted += SetNextParent;
 63        }
 30264    }
 65
 66    private void SetNextParent()
 67    {
 59268        if (cameraController != null)
 69        {
 59270            cameraController.onCameraBlendFinished -= SetNextParent;
 59271            cameraController.onCameraBlendStarted -= SetNextParent;
 72        }
 73
 59274        transform.SetParent(nextParent);
 59275    }
 76}