< 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
 14515        if (cameraPosition != null)
 16        {
 12517            transform.position = cameraPosition.position;
 18        }
 14519        initialParent = transform.parent;
 14520        firtPersonParent = Camera.main.transform;
 21
 22        // Listen to changes on the camera mode
 14523        CommonScriptableObjects.cameraMode.OnChange += OnCameraModeChange;
 24
 25        // Trigger the initial camera set
 14526        OnCameraModeChange(CommonScriptableObjects.cameraMode, CommonScriptableObjects.cameraMode);
 27
 28        //There is no blend in the first set so we parent to the correct initial transform
 14529        SetNextParent();
 14530    }
 31
 13432    private void UpdateForward(Vector3 newForward, Vector3 prev) { transform.forward = newForward; }
 33
 34    private void OnDestroy()
 35    {
 14436        CommonScriptableObjects.cameraMode.OnChange -= OnCameraModeChange;
 14437        CommonScriptableObjects.cameraForward.OnChange -= UpdateForward;
 14438    }
 39
 40    private void OnCameraModeChange(CameraMode.ModeId newMode, CameraMode.ModeId prev)
 41    {
 16342        CommonScriptableObjects.cameraForward.OnChange -= UpdateForward;
 43
 16344        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        {
 1854            if (newMode == CameraMode.ModeId.ThirdPerson)
 155                transform.forward = initialParent.forward;
 56
 1857            nextParent = initialParent;
 58
 1859            if (cameraController != null)
 060                cameraController.onCameraBlendStarted += SetNextParent;
 61        }
 16362    }
 63
 64    private void SetNextParent()
 65    {
 14566        if (cameraController != null)
 67        {
 068            cameraController.onCameraBlendFinished -= SetNextParent;
 069            cameraController.onCameraBlendStarted -= SetNextParent;
 70        }
 14571        transform.SetParent(nextParent);
 14572    }
 73}