< Summary

Class:DCL.Builder.CameraController
Assembly:BuilderInWorld
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/CameraController.cs
Covered lines:27
Uncovered lines:13
Coverable lines:40
Total lines:94
Line coverage:67.5% (27 of 40)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CameraController()0%110100%
Initialize(...)0%3.473062.5%
Dispose()0%110100%
TakeSceneScreenshot(...)0%110100%
TakeSceneScreenshotFromResetPosition(...)0%110100%
ActivateCamera(...)0%4.134080%
DeactivateCamera()0%3.333066.67%
GetLastScreenshot()0%2100%
GetInitialCameraPosition(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/CameraController.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using DCL.Builder;
 4using DCL.Camera;
 5using DCL.Controllers;
 6using DCL.Helpers;
 7using UnityEngine;
 8
 9namespace DCL.Builder
 10{
 11    public class CameraController : ICameraController
 12    {
 313        private float initialEagleCameraHeight = 10f;
 314        private float initialEagleCameraDistance = 10f;
 15
 16        private CameraMode.ModeId avatarCameraModeBeforeEditing;
 17        private Camera.CameraController cameraController;
 18        internal IFreeCameraMovement freeCameraController;
 19        internal IContext context;
 20        internal Texture2D lastScreenshot;
 21
 22        public void Initialize(IContext context)
 23        {
 324            this.context = context;
 325            if (context.sceneReferences.cameraController != null)
 26            {
 027                if(context.sceneReferences.cameraController.GetComponent<Camera.CameraController>().TryGetCameraStateByT
 028                    freeCameraController = (FreeCameraMovement) cameraState;
 29
 030                cameraController = context.sceneReferences.cameraController.GetComponent<Camera.CameraController>();
 31            }
 32
 333            initialEagleCameraHeight = context.editorContext.godModeDynamicVariablesAsset.initialEagleCameraHeight;
 334            initialEagleCameraDistance = context.editorContext.godModeDynamicVariablesAsset.initialEagleCameraDistance;
 335        }
 36
 637        public void Dispose() { DeactivateCamera(); }
 38
 39        public void TakeSceneScreenshot(IFreeCameraMovement.OnSnapshotsReady onSuccess)
 40        {
 41            //We deselect the entities to take better photos
 142            context.editorContext.entityHandler.DeselectEntities();
 143            freeCameraController.TakeSceneScreenshot((sceneSnapshot) =>
 44            {
 045                lastScreenshot = sceneSnapshot;
 046                onSuccess?.Invoke(sceneSnapshot);
 047            });
 148        }
 49
 50        public void TakeSceneScreenshotFromResetPosition(IFreeCameraMovement.OnSnapshotsReady onSuccess)
 51        {
 52            //We deselect the entities to take better photos
 153            context.editorContext.entityHandler.DeselectEntities();
 154            freeCameraController.TakeSceneScreenshotFromResetPosition((sceneSnapshot) =>
 55            {
 056                lastScreenshot = sceneSnapshot;
 057                onSuccess?.Invoke(sceneSnapshot);
 058            });
 159        }
 60
 61        public void ActivateCamera(IParcelScene parcelScene)
 62        {
 163            freeCameraController.gameObject.SetActive(true);
 164            Vector3 pointToLookAt = BIWUtils.CalculateUnityMiddlePoint(parcelScene);
 165            Vector3 cameraPosition = GetInitialCameraPosition(parcelScene);
 166            freeCameraController.SetPosition(cameraPosition);
 167            freeCameraController.LookAt(pointToLookAt);
 168            freeCameraController.SetResetConfiguration(cameraPosition, pointToLookAt);
 69
 170            if (cameraController != null && cameraController.currentCameraState.cameraModeId != CameraMode.ModeId.Buildi
 071                avatarCameraModeBeforeEditing = cameraController.currentCameraState.cameraModeId;
 72
 173            cameraController?.SetCameraMode(CameraMode.ModeId.BuildingToolGodMode);
 074        }
 75
 76        public void DeactivateCamera()
 77        {
 378            if (!DataStore.i.common.isApplicationQuitting.Get())
 379                cameraController?.SetCameraMode(avatarCameraModeBeforeEditing);
 080        }
 81
 082        public Texture2D GetLastScreenshot() { return lastScreenshot;}
 83
 84        internal Vector3 GetInitialCameraPosition(IParcelScene parcelScene)
 85        {
 186            Vector3 middlePoint = BIWUtils.CalculateUnityMiddlePoint(parcelScene);
 187            Vector3 direction = (parcelScene.GetSceneTransform().position - middlePoint).normalized;
 88
 189            return parcelScene.GetSceneTransform().position
 90                   + direction * initialEagleCameraDistance
 91                   + Vector3.up * initialEagleCameraHeight;
 92        }
 93    }
 94}