< 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:75
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, firstPersonParent, initialParent;
 11
 12    private void Awake()
 13    {
 14        // Assign the camera position to the game object
 61015        if (cameraPosition != null)
 16        {
 61017            transform.position = cameraPosition.position;
 61018            firstPersonParent = cameraPosition;
 19        }
 20
 61021        initialParent = transform.parent;
 22
 23        // Listen to changes on the camera mode
 61024        CommonScriptableObjects.cameraMode.OnChange += OnCameraModeChange;
 25
 26        // Trigger the initial camera set
 61027        OnCameraModeChange(CommonScriptableObjects.cameraMode, CommonScriptableObjects.cameraMode);
 28
 29        //There is no blend in the first set so we parent to the correct initial transform
 61030        SetNextParent();
 61031    }
 32
 26233    private void UpdateForward(Vector3 newForward, Vector3 prev) { transform.forward = newForward; }
 34
 35    private void OnDestroy()
 36    {
 61037        CommonScriptableObjects.cameraMode.OnChange -= OnCameraModeChange;
 61038        CommonScriptableObjects.cameraForward.OnChange -= UpdateForward;
 61039    }
 40
 41    private void OnCameraModeChange(CameraMode.ModeId newMode, CameraMode.ModeId prev)
 42    {
 61243        CommonScriptableObjects.cameraForward.OnChange -= UpdateForward;
 44
 61245        if (newMode == CameraMode.ModeId.FirstPerson)
 46        {
 50747            CommonScriptableObjects.cameraForward.OnChange += UpdateForward;
 50748            nextParent = firstPersonParent;
 49
 50750            if (cameraController != null)
 50751                cameraController.onCameraBlendFinished += SetNextParent;
 50752        }
 53        else
 54        {
 10555            if (newMode == CameraMode.ModeId.ThirdPerson)
 10556                transform.forward = initialParent.forward;
 57
 10558            nextParent = initialParent;
 59
 10560            if (cameraController != null)
 10561                cameraController.onCameraBlendStarted += SetNextParent;
 62        }
 10563    }
 64
 65    private void SetNextParent()
 66    {
 61167        if (cameraController != null)
 68        {
 61169            cameraController.onCameraBlendFinished -= SetNextParent;
 61170            cameraController.onCameraBlendStarted -= SetNextParent;
 71        }
 72
 61173        transform.SetParent(nextParent);
 61174    }
 75}