< 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:73
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 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        {
 12417            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    {
 16442        CommonScriptableObjects.cameraForward.OnChange -= UpdateForward;
 43
 16444        if (newMode == CameraMode.ModeId.FirstPerson)
 45        {
 12246            CommonScriptableObjects.cameraForward.OnChange += UpdateForward;
 12247            nextParent = firtPersonParent;
 48
 12249            if (cameraController != null)
 10650                cameraController.onCameraBlendFinished += SetNextParent;
 10651        }
 52        else
 53        {
 4254            if (newMode == CameraMode.ModeId.ThirdPerson)
 2455                transform.forward = initialParent.forward;
 56
 4257            nextParent = initialParent;
 58
 4259            if (cameraController != null)
 3660                cameraController.onCameraBlendStarted += SetNextParent;
 61        }
 5862    }
 63
 64    private void SetNextParent()
 65    {
 14766        if (cameraController != null)
 67        {
 12668            cameraController.onCameraBlendFinished -= SetNextParent;
 12669            cameraController.onCameraBlendStarted -= SetNextParent;
 70        }
 14771        transform.SetParent(nextParent);
 14772    }
 73}