< Summary

Class:DCL.Camera.FreeCameraMovement
Assembly:BuilderInWorld
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/States/EditorMode/FreeCameraController/FreeCameraMovement.cs
Covered lines:259
Uncovered lines:52
Coverable lines:311
Total lines:659
Line coverage:83.2% (259 of 311)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
FreeCameraMovement()0%110100%
Awake()0%10100100%
UpdateLocalGeneralSettings(...)0%2100%
StartDetectingMovement()0%2100%
HasBeenMovement()0%2100%
StopDetectingMovement()0%2100%
OnInputMouseUp(...)0%6200%
OnInputMouseDown(...)0%2.032080%
OnDestroy()0%14140100%
Update()0%110100%
HandleCameraMovement()0%3.213071.43%
HandleCameraLook()0%2.062075%
HandleCameraPan()0%3.073080%
HandleCameraMovementInput()0%14140100%
GetTotalVelocity(...)0%3.583060%
SetCameraCanMove(...)0%2100%
MouseWheel(...)0%3.13077.78%
MouseDragRaw(...)0%330100%
MouseDrag(...)0%440100%
CameraDrag(...)0%2.022083.33%
CameraLook(...)0%4.594066.67%
OnGetRotation()0%110100%
FocusOnEntities(...)0%9.738070%
SetPosition(...)0%110100%
LookAt(...)0%110100%
LookAt(...)0%110100%
SmoothLookAt(...)0%2100%
SmoothLookAt(...)0%2.062075%
FindMidPoint(...)0%660100%
SmoothScroll()0%4.024088.89%
SmoothFocusOnTarget()0%5.055087.5%
SmoothLookAtCorutine()0%4.594066.67%
SetResetConfiguration(...)0%110100%
SetResetConfiguration(...)0%2100%
ResetCameraPosition()0%110100%
TakeSceneScreenshot(...)0%110100%
TakeSceneScreenshotCoroutine()0%550100%
TakeSceneScreenshotFromResetPosition(...)0%2100%
TakeSceneScreenshotFromResetPositionCoroutine()0%20400%
ScreenshotFromCamera(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/States/EditorMode/FreeCameraController/FreeCameraMovement.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using DCL.SettingsCommon;
 5using UnityEngine;
 6
 7namespace DCL.Camera
 8{
 9    public class FreeCameraMovement : CameraStateBase, IFreeCameraMovement
 10    {
 11        private const float CAMERA_ANGLE_THRESHOLD = 0.01f;
 12        private const float CAMERA_PAN_THRESHOLD = 0.001f;
 13        private const float CAMERA_MOVEMENT_THRESHOLD = 0.001f;
 14
 15        private const float CAMERA_MOVEMENT_DEACTIVATE_INPUT_MAGNITUD = 0.001f;
 16
 17        private const int SCENE_SNAPSHOT_WIDTH_RES = 854;
 18        private const int SCENE_SNAPSHOT_HEIGHT_RES = 480;
 19
 61220        public float focusDistance = 5f;
 21
 22        [Header("Camera Movement")]
 61223        public float xPlaneSpeedPercentCompensantion = 0.85f;
 24
 61225        public float movementSpeed = 5f;
 61226        public float lerpTime = 0.3F;
 27
 61228        public float lerpDeccelerationTime = 0.3F;
 61229        public float initalAcceleration = 2f;
 61230        public float speedClamp = 1f;
 31
 32        [Header("Camera Look")]
 61233        public float smoothLookAtSpeed = 5f;
 34
 61235        public float smoothCameraLookSpeed = 5f;
 61236        public float lookSpeedH = 2f;
 61237        public float lookSpeedV = 2f;
 38
 39        [Header("Camera Pan")]
 61240        public float smoothCameraPanAceleration = 5f;
 41
 61242        public float dragSpeed = 3f;
 43
 44        [Header("Camera Zoom")]
 61245        public float zoomSpeed = 2f;
 46
 47        [Header("InputActions")]
 48        [SerializeField] internal InputAction_Hold advanceFowardInputAction;
 49
 50        [SerializeField] internal InputAction_Hold advanceBackInputAction;
 51        [SerializeField] internal InputAction_Hold advanceLeftInputAction;
 52        [SerializeField] internal InputAction_Hold advanceRightInputAction;
 53        [SerializeField] internal InputAction_Hold advanceUpInputAction;
 54        [SerializeField] internal InputAction_Hold advanceDownInputAction;
 55        [SerializeField] internal InputAction_Hold cameraPanInputAction;
 56        [SerializeField] internal InputAction_Trigger zoomInFromKeyboardInputAction;
 57        [SerializeField] internal InputAction_Trigger zoomOutFromKeyboardInputAction;
 58
 61259        internal Vector3 direction = Vector3.zero;
 60
 61        internal float yaw = 0f;
 62        internal float pitch = 0f;
 63
 64        internal float panAxisX = 0f;
 65        internal float panAxisY = 0f;
 66
 61267        internal bool isCameraAbleToMove = true;
 68
 69        internal bool isAdvancingForward = false;
 70        internal bool isAdvancingBackward = false;
 71        internal bool isAdvancingLeft = false;
 72        internal bool isAdvancingRight = false;
 73        internal bool isAdvancingUp = false;
 74        internal bool isAdvancingDown = false;
 75
 76        internal bool isDetectingMovement = false;
 77        internal bool hasBeenMovement = false;
 78
 79        internal bool isPanCameraActive = false;
 80        internal bool isMouseRightClickDown = false;
 81
 82        internal Coroutine smoothLookAtCoroutine;
 83        internal Coroutine smoothFocusOnTargetCoroutine;
 84        internal Coroutine smoothScrollCoroutine;
 85        internal Coroutine takeScreenshotCoroutine;
 86
 87        private InputAction_Hold.Started advanceForwardStartDelegate;
 88        private InputAction_Hold.Finished advanceForwardFinishedDelegate;
 89
 90        private InputAction_Hold.Started advanceBackStartDelegate;
 91        private InputAction_Hold.Finished advanceBackFinishedDelegate;
 92
 93        private InputAction_Hold.Started advanceLeftStartDelegate;
 94        private InputAction_Hold.Finished advanceLeftFinishedDelegate;
 95
 96        private InputAction_Hold.Started advanceRightStartDelegate;
 97        private InputAction_Hold.Finished advanceRightFinishedDelegate;
 98
 99        private InputAction_Hold.Started advanceDownStartDelegate;
 100        private InputAction_Hold.Finished advanceDownFinishedDelegate;
 101
 102        private InputAction_Hold.Started advanceUpStartDelegate;
 103        private InputAction_Hold.Finished advanceUpFinishedDelegate;
 104
 105        private InputAction_Hold.Started cameraPanStartDelegate;
 106        private InputAction_Hold.Finished cameraPanFinishedDelegate;
 107
 108        private InputAction_Trigger.Triggered zoomInFromKeyboardDelegate;
 109        private InputAction_Trigger.Triggered zoomOutFromKeyboardDelegate;
 110
 111        private Vector3 nextTranslation;
 112        internal Vector3 originalCameraPosition;
 113        internal Vector3 originalCameraPointToLookAt;
 612114        private Vector3 cameraVelocity = Vector3.zero;
 115
 116        private float lastMouseWheelTime;
 117        private float cameraPanAdvance;
 118        private float cameraLookAdvance;
 119        internal UnityEngine.Camera screenshotCamera;
 120
 121        public bool invertMouseY = false;
 122
 123        private void Awake()
 124        {
 50125            BIWInputWrapper.OnMouseDrag += MouseDrag;
 50126            BIWInputWrapper.OnMouseDragRaw += MouseDragRaw;
 50127            BIWInputWrapper.OnMouseWheel += MouseWheel;
 128
 50129            BIWInputWrapper.OnMouseDown += OnInputMouseDown;
 50130            BIWInputWrapper.OnMouseUp += OnInputMouseUp;
 131
 50132            advanceForwardStartDelegate = (action) => isAdvancingForward = true;
 50133            advanceForwardFinishedDelegate = (action) => isAdvancingForward = false;
 134
 50135            if (advanceFowardInputAction != null)
 136            {
 36137                advanceFowardInputAction.OnStarted += advanceForwardStartDelegate;
 36138                advanceFowardInputAction.OnFinished += advanceForwardFinishedDelegate;
 139            }
 140
 50141            advanceBackStartDelegate = (action) => isAdvancingBackward = true;
 50142            advanceBackFinishedDelegate = (action) => isAdvancingBackward = false;
 143
 50144            if (advanceBackInputAction != null)
 145            {
 36146                advanceBackInputAction.OnStarted += advanceBackStartDelegate;
 36147                advanceBackInputAction.OnFinished += advanceBackFinishedDelegate;
 148            }
 149
 50150            advanceLeftStartDelegate = (action) => isAdvancingLeft = true;
 50151            advanceLeftFinishedDelegate = (action) => isAdvancingLeft = false;
 152
 50153            if (advanceLeftInputAction != null)
 154            {
 36155                advanceLeftInputAction.OnStarted += advanceLeftStartDelegate;
 36156                advanceLeftInputAction.OnFinished += advanceLeftFinishedDelegate;
 157            }
 158
 50159            advanceRightStartDelegate = (action) => isAdvancingRight = true;
 50160            advanceRightFinishedDelegate = (action) => isAdvancingRight = false;
 161
 50162            if (advanceRightInputAction != null)
 163            {
 36164                advanceRightInputAction.OnStarted += advanceRightStartDelegate;
 36165                advanceRightInputAction.OnFinished += advanceRightFinishedDelegate;
 166            }
 167
 50168            advanceUpStartDelegate = (action) => isAdvancingUp = true;
 50169            advanceUpFinishedDelegate = (action) => isAdvancingUp = false;
 170
 50171            if (advanceUpInputAction != null)
 172            {
 36173                advanceUpInputAction.OnStarted += advanceUpStartDelegate;
 36174                advanceUpInputAction.OnFinished += advanceUpFinishedDelegate;
 175            }
 176
 50177            advanceDownStartDelegate = (action) => isAdvancingDown = true;
 50178            advanceDownFinishedDelegate = (action) => isAdvancingDown = false;
 179
 50180            if (advanceDownInputAction != null)
 181            {
 36182                advanceDownInputAction.OnStarted += advanceDownStartDelegate;
 36183                advanceDownInputAction.OnFinished += advanceDownFinishedDelegate;
 184            }
 185
 50186            cameraPanStartDelegate = (action) => isPanCameraActive = true;
 50187            cameraPanFinishedDelegate = (action) => isPanCameraActive = false;
 188
 50189            if (cameraPanInputAction != null)
 190            {
 36191                cameraPanInputAction.OnStarted += cameraPanStartDelegate;
 36192                cameraPanInputAction.OnFinished += cameraPanFinishedDelegate;
 193            }
 194
 50195            zoomInFromKeyboardDelegate = (action) => MouseWheel(1f);
 196
 50197            if (zoomInFromKeyboardInputAction != null)
 36198                zoomInFromKeyboardInputAction.OnTriggered += zoomInFromKeyboardDelegate;
 199
 50200            zoomOutFromKeyboardDelegate = (action) => MouseWheel(-1f);
 201
 50202            if (zoomOutFromKeyboardInputAction != null)
 36203                zoomOutFromKeyboardInputAction.OnTriggered += zoomOutFromKeyboardDelegate;
 204
 50205            invertMouseY = Settings.i.generalSettings.Data.invertYAxis;
 206
 50207            Settings.i.generalSettings.OnChanged += UpdateLocalGeneralSettings;
 50208        }
 209
 210        private void UpdateLocalGeneralSettings(GeneralSettings obj)
 211        {
 0212            invertMouseY = obj.invertYAxis;
 0213        }
 214
 215        public void StartDetectingMovement()
 216        {
 0217            isDetectingMovement = true;
 0218            hasBeenMovement = false;
 0219        }
 220
 0221        public bool HasBeenMovement() { return hasBeenMovement; }
 222
 0223        public void StopDetectingMovement() { isDetectingMovement = false; }
 224
 225        internal void OnInputMouseUp(int buttonId, Vector3 mousePosition)
 226        {
 0227            if (buttonId != 1)
 0228                return;
 229
 0230            isMouseRightClickDown = false;
 0231        }
 232
 233        internal void OnInputMouseDown(int buttonId, Vector3 mousePosition)
 234        {
 1235            if (buttonId != 1)
 0236                return;
 237
 1238            isMouseRightClickDown = true;
 1239            direction = Vector3.zero;
 1240        }
 241
 242        private void OnDestroy()
 243        {
 50244            BIWInputWrapper.OnMouseDrag -= MouseDrag;
 50245            BIWInputWrapper.OnMouseDragRaw -= MouseDragRaw;
 50246            BIWInputWrapper.OnMouseWheel -= MouseWheel;
 247
 50248            BIWInputWrapper.OnMouseDown -= OnInputMouseDown;
 50249            BIWInputWrapper.OnMouseUp -= OnInputMouseUp;
 250
 50251            if (advanceFowardInputAction != null)
 252            {
 36253                advanceFowardInputAction.OnStarted -= advanceForwardStartDelegate;
 36254                advanceFowardInputAction.OnFinished -= advanceForwardFinishedDelegate;
 255            }
 256
 50257            if (advanceBackInputAction != null)
 258            {
 36259                advanceBackInputAction.OnStarted -= advanceBackStartDelegate;
 36260                advanceBackInputAction.OnFinished -= advanceBackFinishedDelegate;
 261            }
 262
 50263            if (advanceLeftInputAction != null)
 264            {
 36265                advanceLeftInputAction.OnStarted -= advanceLeftStartDelegate;
 36266                advanceLeftInputAction.OnFinished -= advanceLeftFinishedDelegate;
 267            }
 268
 50269            if (advanceRightInputAction != null)
 270            {
 36271                advanceRightInputAction.OnStarted -= advanceRightStartDelegate;
 36272                advanceRightInputAction.OnFinished -= advanceRightFinishedDelegate;
 273            }
 274
 50275            if (advanceDownInputAction != null)
 276            {
 36277                advanceDownInputAction.OnStarted -= advanceDownStartDelegate;
 36278                advanceDownInputAction.OnFinished -= advanceDownFinishedDelegate;
 279            }
 280
 50281            if (advanceUpInputAction != null)
 282            {
 36283                advanceUpInputAction.OnStarted -= advanceUpStartDelegate;
 36284                advanceUpInputAction.OnFinished -= advanceUpFinishedDelegate;
 285            }
 286
 50287            if (cameraPanInputAction != null)
 288            {
 36289                cameraPanInputAction.OnStarted -= cameraPanStartDelegate;
 36290                cameraPanInputAction.OnFinished -= cameraPanFinishedDelegate;
 291            }
 292
 50293            if (zoomInFromKeyboardInputAction != null)
 36294                zoomInFromKeyboardInputAction.OnTriggered -= zoomInFromKeyboardDelegate;
 295
 50296            if (zoomOutFromKeyboardInputAction != null)
 36297                zoomOutFromKeyboardInputAction.OnTriggered -= zoomOutFromKeyboardDelegate;
 298
 50299            if (smoothScrollCoroutine != null)
 1300                CoroutineStarter.Stop(smoothScrollCoroutine);
 301
 50302            if (smoothLookAtCoroutine != null)
 1303                CoroutineStarter.Stop(smoothLookAtCoroutine);
 304
 50305            if (smoothFocusOnTargetCoroutine != null)
 1306                CoroutineStarter.Stop(smoothFocusOnTargetCoroutine);
 307
 50308            if (takeScreenshotCoroutine != null)
 2309                CoroutineStarter.Stop(takeScreenshotCoroutine);
 310
 50311            Settings.i.generalSettings.OnChanged -= UpdateLocalGeneralSettings;
 50312        }
 313
 314        private void Update()
 315        {
 100316            HandleCameraLook();
 100317            HandleCameraPan();
 100318            HandleCameraMovement();
 100319        }
 320
 321        #region CameraTransformChanges
 322
 323        private void HandleCameraMovement()
 324        {
 100325            HandleCameraMovementInput();
 100326            if (direction.magnitude >= CAMERA_MOVEMENT_DEACTIVATE_INPUT_MAGNITUD)
 0327                nextTranslation = direction;
 100328            nextTranslation = Vector3.Lerp(nextTranslation, Vector3.zero, lerpTime * Time.deltaTime);
 329
 100330            if (nextTranslation.magnitude >= CAMERA_MOVEMENT_THRESHOLD)
 0331                transform.Translate(nextTranslation * (movementSpeed * Time.deltaTime), Space.Self);
 100332        }
 333
 334        private void HandleCameraLook()
 335        {
 100336            Quaternion nextIteration =  Quaternion.Lerp(transform.rotation, Quaternion.Euler(new Vector3(pitch, yaw, 0f)
 337
 100338            if (Mathf.Abs(nextIteration.eulerAngles.magnitude - transform.rotation.eulerAngles.magnitude) >= CAMERA_ANGL
 0339                transform.rotation = nextIteration;
 100340        }
 341
 342        private void HandleCameraPan()
 343        {
 100344            panAxisX = Mathf.Lerp(panAxisX, 0, cameraPanAdvance * Time.deltaTime);
 100345            panAxisY = Mathf.Lerp(panAxisY, 0, cameraPanAdvance * Time.deltaTime);
 346
 100347            if (Mathf.Abs(panAxisX) >= CAMERA_PAN_THRESHOLD || Mathf.Abs(panAxisY) >= CAMERA_PAN_THRESHOLD)
 0348                transform.Translate(panAxisX, panAxisY, 0);
 100349        }
 350
 351        #endregion
 352
 353        internal void HandleCameraMovementInput()
 354        {
 102355            int velocityChangedCount = 0;
 102356            if (isAdvancingForward)
 357            {
 1358                cameraVelocity += GetTotalVelocity(Vector3.forward);
 1359                velocityChangedCount++;
 360            }
 361
 102362            if (isAdvancingBackward)
 363            {
 1364                cameraVelocity += GetTotalVelocity(Vector3.back);
 1365                velocityChangedCount++;
 366            }
 367
 102368            if (!isAdvancingBackward && !isAdvancingForward)
 100369                cameraVelocity.z = Mathf.Lerp(cameraVelocity.z, 0, lerpDeccelerationTime);
 370
 102371            if (isAdvancingRight)
 372            {
 1373                cameraVelocity += GetTotalVelocity(Vector3.right) * xPlaneSpeedPercentCompensantion;
 1374                velocityChangedCount++;
 375            }
 376
 102377            if (isAdvancingLeft)
 378            {
 1379                cameraVelocity += GetTotalVelocity(Vector3.left) * xPlaneSpeedPercentCompensantion;
 1380                velocityChangedCount++;
 381            }
 382
 102383            if (!isAdvancingRight && !isAdvancingLeft)
 100384                cameraVelocity.x = Mathf.Lerp(cameraVelocity.x, 0, lerpDeccelerationTime);
 385
 102386            if (isAdvancingUp)
 387            {
 1388                cameraVelocity += GetTotalVelocity(Vector3.up);
 1389                velocityChangedCount++;
 390            }
 391
 102392            if (isAdvancingDown)
 393            {
 1394                cameraVelocity += GetTotalVelocity(Vector3.down);
 1395                velocityChangedCount++;
 396            }
 397
 102398            if (!isAdvancingUp && !isAdvancingDown)
 100399                cameraVelocity.y = Mathf.Lerp(cameraVelocity.y, 0, lerpDeccelerationTime);
 400
 102401            if (velocityChangedCount != 0)
 2402                cameraVelocity = Vector3.ClampMagnitude(cameraVelocity, speedClamp);
 403
 102404            direction = cameraVelocity;
 102405        }
 406
 407        private Vector3 GetTotalVelocity(Vector3 velocityToAdd)
 408        {
 6409            if (!isMouseRightClickDown)
 0410                return  Vector3.zero;
 411
 6412            if (isDetectingMovement)
 0413                hasBeenMovement = true;
 6414            return velocityToAdd * (initalAcceleration * Time.deltaTime);
 415        }
 416
 0417        public void SetCameraCanMove(bool canMove) { isCameraAbleToMove = canMove; }
 418
 419        internal void MouseWheel(float axis)
 420        {
 1421            if (!isCameraAbleToMove)
 0422                return;
 423
 1424            if (smoothScrollCoroutine != null)
 0425                CoroutineStarter.Stop(smoothScrollCoroutine);
 426
 1427            float delta = Time.time - lastMouseWheelTime;
 1428            float scrollValue = axis * Mathf.Clamp01(delta);
 1429            lastMouseWheelTime = Time.time;
 430
 1431            smoothScrollCoroutine = CoroutineStarter.Start(SmoothScroll(scrollValue));
 1432        }
 433
 434        internal void MouseDragRaw(int buttonId, Vector3 mousePosition, float axisX, float axisY)
 435        {
 1436            if (buttonId == 1 && !isPanCameraActive)
 1437                CameraLook(axisX, axisY);
 1438        }
 439
 440        internal void MouseDrag(int buttonId, Vector3 mousePosition, float axisX, float axisY)
 441        {
 1442            if (buttonId == 2 || buttonId == 1 && isPanCameraActive)
 1443                CameraDrag(axisX, axisY);
 1444        }
 445
 446        private void CameraDrag(float axisX, float axisY)
 447        {
 1448            if (!isCameraAbleToMove)
 0449                return;
 450
 1451            panAxisX += -axisX * Time.deltaTime * dragSpeed;
 1452            panAxisY += -axisY * Time.deltaTime * dragSpeed;
 1453            cameraPanAdvance = smoothCameraPanAceleration;
 1454        }
 455
 456        private void CameraLook(float axisX, float axisY)
 457        {
 1458            if (!isCameraAbleToMove || !isMouseRightClickDown)
 0459                return;
 460
 1461            yaw += lookSpeedH * axisX;
 1462            if (invertMouseY)
 463            {
 0464                pitch -= lookSpeedV * -axisY;
 0465            }
 466            else {
 1467                pitch -= lookSpeedV * axisY;
 468            }
 1469            cameraLookAdvance = smoothCameraLookSpeed * Time.deltaTime;
 1470        }
 471
 1472        public override Vector3 OnGetRotation() { return transform.eulerAngles; }
 473
 474        public void FocusOnEntities(List<BIWEntity> entitiesToFocus)
 475        {
 1476            if (entitiesToFocus.Count <= 0)
 0477                return;
 478
 1479            Vector3 middlePoint = FindMidPoint(entitiesToFocus);
 1480            if (Vector3.positiveInfinity == middlePoint ||
 481                Vector3.negativeInfinity == middlePoint ||
 482                float.IsNaN(middlePoint.x) ||
 483                float.IsNaN(middlePoint.y) ||
 484                float.IsNaN(middlePoint.z))
 0485                return;
 486
 1487            if (smoothFocusOnTargetCoroutine != null)
 0488                CoroutineStarter.Stop(smoothFocusOnTargetCoroutine);
 1489            smoothFocusOnTargetCoroutine = CoroutineStarter.Start(SmoothFocusOnTarget(middlePoint));
 1490            SmoothLookAt(middlePoint);
 1491        }
 492
 2493        public void SetPosition(Vector3 position) { transform.position = position; }
 494
 495        public void LookAt(Transform transformToLookAt)
 496        {
 36497            LookAt(transformToLookAt.position);
 36498        }
 499
 500        public void LookAt(Vector3 pointToLookAt)
 501        {
 37502            transform.LookAt(pointToLookAt);
 37503            yaw = transform.eulerAngles.y;
 37504            pitch = transform.eulerAngles.x;
 37505        }
 506
 0507        public void SmoothLookAt(Transform transformToLookAt) { SmoothLookAt(transformToLookAt.position); }
 508
 509        public void SmoothLookAt(Vector3 position)
 510        {
 1511            if (smoothLookAtCoroutine != null)
 0512                CoroutineStarter.Stop(smoothLookAtCoroutine);
 1513            smoothLookAtCoroutine = CoroutineStarter.Start(SmoothLookAtCorutine(position));
 1514        }
 515
 516        Vector3 FindMidPoint(List<BIWEntity> entitiesToLook)
 517        {
 1518            Vector3 finalPosition = Vector3.zero;
 1519            int totalPoints = 0;
 4520            foreach (BIWEntity entity in entitiesToLook)
 521            {
 1522                if (entity.rootEntity.meshRootGameObject && entity.rootEntity.meshesInfo.renderers.Length > 0)
 523                {
 1524                    Vector3 midPointFromEntity = Vector3.zero;
 4525                    foreach (Renderer render in entity.rootEntity.renderers)
 526                    {
 1527                        if (render == null)
 528                            continue;
 1529                        midPointFromEntity += render.bounds.center;
 530                    }
 531
 1532                    midPointFromEntity /= entity.rootEntity.renderers.Length;
 1533                    finalPosition += midPointFromEntity;
 1534                    totalPoints++;
 535                }
 536            }
 537
 1538            finalPosition /= totalPoints;
 1539            return finalPosition;
 540        }
 541
 542        IEnumerator SmoothScroll(float axis)
 543        {
 1544            float scrollMovementDestination = axis * zoomSpeed;
 545
 1546            Vector3 targetPosition = transform.position + transform.TransformDirection(Vector3.forward * scrollMovementD
 547
 1548            float advance = 0;
 1549            while (advance <= 1)
 550            {
 1551                advance += smoothLookAtSpeed * Time.deltaTime;
 1552                Vector3 result = Vector3.Lerp(transform.position, targetPosition, advance);
 1553                transform.position = result;
 1554                yield return null;
 555            }
 0556        }
 557
 558        IEnumerator SmoothFocusOnTarget(Vector3 targetPosition)
 559        {
 1560            float advance = 0;
 17561            while (advance <= 1)
 562            {
 17563                advance += smoothLookAtSpeed * Time.deltaTime;
 17564                transform.position = Vector3.Lerp(transform.position, targetPosition, advance);
 17565                if (Vector3.Distance(transform.position, targetPosition) <= focusDistance)
 1566                    yield break;
 16567                yield return null;
 568            }
 0569        }
 570
 571        IEnumerator SmoothLookAtCorutine(Vector3 targetPosition)
 572        {
 1573            Quaternion targetRotation = Quaternion.LookRotation(targetPosition - transform.position);
 1574            float advance = 0;
 24575            while (advance <= 1)
 576            {
 24577                advance += smoothLookAtSpeed * Time.deltaTime;
 24578                transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, advance);
 24579                yield return null;
 580            }
 581
 0582            yaw = transform.eulerAngles.y;
 0583            pitch = transform.eulerAngles.x;
 0584        }
 585
 586        public void SetResetConfiguration(Vector3 position, Transform lookAt)
 587        {
 38588            SetResetConfiguration(position, lookAt.position);
 38589        }
 590
 591        public void SetResetConfiguration(Vector3 position, Vector3 pointToLook)
 592        {
 0593            originalCameraPosition = position;
 0594            originalCameraPointToLookAt = pointToLook;
 0595        }
 596
 597        public void ResetCameraPosition()
 598        {
 1599            SetPosition(originalCameraPosition);
 1600            LookAt(originalCameraPointToLookAt);
 1601            direction = Vector3.zero;
 1602        }
 603
 4604        public void TakeSceneScreenshot(IFreeCameraMovement.OnSnapshotsReady onSuccess) { takeScreenshotCoroutine = Coro
 605
 606        private IEnumerator TakeSceneScreenshotCoroutine(IFreeCameraMovement.OnSnapshotsReady callback)
 607        {
 2608            UnityEngine.Camera camera = UnityEngine.Camera.main;
 2609            if (screenshotCamera != null)
 2610                camera = screenshotCamera;
 611
 2612            var current = camera.targetTexture;
 2613            camera.targetTexture = null;
 614
 2615            yield return null;
 616
 2617            Texture2D sceneScreenshot = ScreenshotFromCamera(camera, SCENE_SNAPSHOT_WIDTH_RES, SCENE_SNAPSHOT_HEIGHT_RES
 2618            camera.targetTexture = current;
 2619            callback?.Invoke(sceneScreenshot);
 2620        }
 621
 0622        public void TakeSceneScreenshotFromResetPosition(IFreeCameraMovement.OnSnapshotsReady onSuccess) { StartCoroutin
 623
 624        private IEnumerator TakeSceneScreenshotFromResetPositionCoroutine(IFreeCameraMovement.OnSnapshotsReady callback)
 625        {
 626            // Store current camera position/direction
 0627            Vector3 currentPos = transform.position;
 0628            Vector3 currentLookAt = transform.forward;
 0629            SetPosition(originalCameraPosition);
 0630            transform.LookAt(originalCameraPointToLookAt);
 631
 0632            var current = camera.targetTexture;
 0633            camera.targetTexture = null;
 634
 0635            yield return null;
 636
 0637            Texture2D sceneScreenshot = ScreenshotFromCamera(camera, SCENE_SNAPSHOT_WIDTH_RES, SCENE_SNAPSHOT_HEIGHT_RES
 0638            camera.targetTexture = current;
 0639            callback?.Invoke(sceneScreenshot);
 640
 641            // Restore camera position/direction after the screenshot
 0642            SetPosition(currentPos);
 0643            transform.forward = currentLookAt;
 0644        }
 645
 646        private Texture2D ScreenshotFromCamera(UnityEngine.Camera cameraToScreenshot, int width, int height)
 647        {
 2648            RenderTexture rt = new RenderTexture(width, height, 32);
 2649            cameraToScreenshot.targetTexture = rt;
 2650            Texture2D screenShot = new Texture2D(rt.width, rt.height, TextureFormat.RGBA32, false);
 2651            cameraToScreenshot.Render();
 2652            RenderTexture.active = rt;
 2653            screenShot.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
 2654            screenShot.Apply();
 655
 2656            return screenShot;
 657        }
 658    }
 659}

Methods/Properties

FreeCameraMovement()
Awake()
UpdateLocalGeneralSettings(DCL.SettingsCommon.GeneralSettings)
StartDetectingMovement()
HasBeenMovement()
StopDetectingMovement()
OnInputMouseUp(System.Int32, UnityEngine.Vector3)
OnInputMouseDown(System.Int32, UnityEngine.Vector3)
OnDestroy()
Update()
HandleCameraMovement()
HandleCameraLook()
HandleCameraPan()
HandleCameraMovementInput()
GetTotalVelocity(UnityEngine.Vector3)
SetCameraCanMove(System.Boolean)
MouseWheel(System.Single)
MouseDragRaw(System.Int32, UnityEngine.Vector3, System.Single, System.Single)
MouseDrag(System.Int32, UnityEngine.Vector3, System.Single, System.Single)
CameraDrag(System.Single, System.Single)
CameraLook(System.Single, System.Single)
OnGetRotation()
FocusOnEntities(System.Collections.Generic.List[BIWEntity])
SetPosition(UnityEngine.Vector3)
LookAt(UnityEngine.Transform)
LookAt(UnityEngine.Vector3)
SmoothLookAt(UnityEngine.Transform)
SmoothLookAt(UnityEngine.Vector3)
FindMidPoint(System.Collections.Generic.List[BIWEntity])
SmoothScroll()
SmoothFocusOnTarget()
SmoothLookAtCorutine()
SetResetConfiguration(UnityEngine.Vector3, UnityEngine.Transform)
SetResetConfiguration(UnityEngine.Vector3, UnityEngine.Vector3)
ResetCameraPosition()
TakeSceneScreenshot(DCL.Camera.IFreeCameraMovement/OnSnapshotsReady)
TakeSceneScreenshotCoroutine()
TakeSceneScreenshotFromResetPosition(DCL.Camera.IFreeCameraMovement/OnSnapshotsReady)
TakeSceneScreenshotFromResetPositionCoroutine()
ScreenshotFromCamera(UnityEngine.Camera, System.Int32, System.Int32)