< 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
 14715        if (cameraPosition != null)
 16        {
 12617            transform.position = cameraPosition.position;
 18        }
 14719        initialParent = transform.parent;
 14720        firtPersonParent = Camera.main.transform;
 21
 22        // Listen to changes on the camera mode
 14723        CommonScriptableObjects.cameraMode.OnChange += OnCameraModeChange;
 24
 25        // Trigger the initial camera set
 14726        OnCameraModeChange(CommonScriptableObjects.cameraMode, CommonScriptableObjects.cameraMode);
 27
 28        //There is no blend in the first set so we parent to the correct initial transform
 14729        SetNextParent();
 14730    }
 31
 42232    private void UpdateForward(Vector3 newForward, Vector3 prev) { transform.forward = newForward; }
 33
 34    private void OnDestroy()
 35    {
 14636        CommonScriptableObjects.cameraMode.OnChange -= OnCameraModeChange;
 14637        CommonScriptableObjects.cameraForward.OnChange -= UpdateForward;
 14638    }
 39
 40    private void OnCameraModeChange(CameraMode.ModeId newMode, CameraMode.ModeId prev)
 41    {
 15042        CommonScriptableObjects.cameraForward.OnChange -= UpdateForward;
 43
 15044        if (newMode == CameraMode.ModeId.FirstPerson)
 45        {
 12646            CommonScriptableObjects.cameraForward.OnChange += UpdateForward;
 12647            nextParent = firtPersonParent;
 48
 12649            if (cameraController != null)
 11050                cameraController.onCameraBlendFinished += SetNextParent;
 11051        }
 52        else
 53        {
 2454            if (newMode == CameraMode.ModeId.ThirdPerson)
 2455                transform.forward = initialParent.forward;
 56
 2457            nextParent = initialParent;
 58
 2459            if (cameraController != null)
 1860                cameraController.onCameraBlendStarted += SetNextParent;
 61        }
 4062    }
 63
 64    private void SetNextParent()
 65    {
 14966        if (cameraController != null)
 67        {
 12868            cameraController.onCameraBlendFinished -= SetNextParent;
 12869            cameraController.onCameraBlendStarted -= SetNextParent;
 70        }
 14971        transform.SetParent(nextParent);
 14972    }
 73}