< Summary

Class:FirstPersonCameraEntityReference
Assembly:FirstPersonCameraEntity
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/CharacterController/FirstPersonCameraReference/FirstPersonCameraEntityReference.cs
Covered lines:25
Uncovered lines:5
Coverable lines:30
Total lines:73
Line coverage:83.3% (25 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%5.315076.92%
SetNextParent()0%2.262060%

File(s)

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

#LineLine coverage
 1using System;
 2using DCL.Camera;
 3using UnityEngine;
 4
 5public class FirstPersonCameraEntityReference : MonoBehaviour
 6{
 7    public CameraController cameraController;
 8    public Transform cameraPosition;
 9
 10    private Transform nextParent, firtPersonParent, initialParent;
 11
 12    private void Awake()
 13    {
 14        // Assign the camera position to the game object
 14615        if (cameraPosition != null)
 16        {
 12417            transform.position = cameraPosition.position;
 18        }
 14619        initialParent = transform.parent;
 14620        firtPersonParent = Camera.main.transform;
 21
 22        // Listen to changes on the camera mode
 14623        CommonScriptableObjects.cameraMode.OnChange += OnCameraModeChange;
 24
 25        // Trigger the initial camera set
 14626        OnCameraModeChange(CommonScriptableObjects.cameraMode, CommonScriptableObjects.cameraMode);
 27
 28        //There is no blend in the first set so we parent to the correct initial transform
 14629        SetNextParent();
 14630    }
 31
 13832    private void UpdateForward(Vector3 newForward, Vector3 prev) { transform.forward = newForward; }
 33
 34    private void OnDestroy()
 35    {
 14536        CommonScriptableObjects.cameraMode.OnChange -= OnCameraModeChange;
 14537        CommonScriptableObjects.cameraForward.OnChange -= UpdateForward;
 14538    }
 39
 40    private void OnCameraModeChange(CameraMode.ModeId newMode, CameraMode.ModeId prev)
 41    {
 16442        CommonScriptableObjects.cameraForward.OnChange -= UpdateForward;
 43
 16444        if (newMode == CameraMode.ModeId.FirstPerson)
 45        {
 14546            CommonScriptableObjects.cameraForward.OnChange += UpdateForward;
 14547            nextParent = firtPersonParent;
 48
 14549            if (cameraController != null)
 050                cameraController.onCameraBlendFinished += SetNextParent;
 051        }
 52        else
 53        {
 1954            if (newMode == CameraMode.ModeId.ThirdPerson)
 155                transform.forward = initialParent.forward;
 56
 1957            nextParent = initialParent;
 58
 1959            if (cameraController != null)
 060                cameraController.onCameraBlendStarted += SetNextParent;
 61        }
 16462    }
 63
 64    private void SetNextParent()
 65    {
 14666        if (cameraController != null)
 67        {
 068            cameraController.onCameraBlendFinished -= SetNextParent;
 069            cameraController.onCameraBlendStarted -= SetNextParent;
 70        }
 14671        transform.SetParent(nextParent);
 14672    }
 73}