< 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:239
Uncovered lines:42
Coverable lines:281
Total lines:600
Line coverage:85% (239 of 281)
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%4.943040%
OnInputMouseDown(...)0%2.032080%
OnDestroy()0%13130100%
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%4.184077.78%
MouseDragRaw(...)0%330100%
MouseDrag(...)0%440100%
CameraDrag(...)0%2.012085.71%
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%

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.Configuration;
 5using DCL.SettingsCommon;
 6using UnityEngine;
 7
 8namespace DCL.Camera
 9{
 10    public class FreeCameraMovement : CameraStateBase, IFreeCameraMovement
 11    {
 12        private const float CAMERA_ANGLE_THRESHOLD = 0.01f;
 13        private const float CAMERA_PAN_THRESHOLD = 0.001f;
 14        private const float CAMERA_MOVEMENT_THRESHOLD = 0.001f;
 15
 16        private const float CAMERA_MOVEMENT_DEACTIVATE_INPUT_MAGNITUD = 0.001f;
 17
 62318        public float focusDistance = 5f;
 19
 20        [Header("Camera Movement")]
 62321        public float xPlaneSpeedPercentCompensantion = 0.85f;
 22
 62323        public float movementSpeed = 5f;
 62324        public float lerpTime = 0.3F;
 25
 62326        public float lerpDeccelerationTime = 0.3F;
 62327        public float initalAcceleration = 2f;
 62328        public float speedClamp = 1f;
 29
 30        [Header("Camera Look")]
 62331        public float smoothLookAtSpeed = 5f;
 32
 62333        public float smoothCameraLookSpeed = 5f;
 62334        public float lookSpeedH = 2f;
 62335        public float lookSpeedV = 2f;
 36
 37        [Header("Camera Pan")]
 62338        public float smoothCameraPanAceleration = 5f;
 39
 62340        public float dragSpeed = 3f;
 41
 42        [Header("Camera Zoom")]
 62343        public float zoomSpeed = 2f;
 44
 45        [Header("InputActions")]
 46        [SerializeField] internal InputAction_Hold advanceFowardInputAction;
 47
 48        [SerializeField] internal InputAction_Hold advanceBackInputAction;
 49        [SerializeField] internal InputAction_Hold advanceLeftInputAction;
 50        [SerializeField] internal InputAction_Hold advanceRightInputAction;
 51        [SerializeField] internal InputAction_Hold advanceUpInputAction;
 52        [SerializeField] internal InputAction_Hold advanceDownInputAction;
 53        [SerializeField] internal InputAction_Hold cameraPanInputAction;
 54        [SerializeField] internal InputAction_Trigger zoomInFromKeyboardInputAction;
 55        [SerializeField] internal InputAction_Trigger zoomOutFromKeyboardInputAction;
 56
 62357        internal Vector3 direction = Vector3.zero;
 58
 59        internal float yaw = 0f;
 60        internal float pitch = 0f;
 61
 62        internal float panAxisX = 0f;
 63        internal float panAxisY = 0f;
 64
 62365        internal bool isCameraAbleToMove = true;
 66
 67        internal bool isAdvancingForward = false;
 68        internal bool isAdvancingBackward = false;
 69        internal bool isAdvancingLeft = false;
 70        internal bool isAdvancingRight = false;
 71        internal bool isAdvancingUp = false;
 72        internal bool isAdvancingDown = false;
 73
 74        internal bool isDetectingMovement = false;
 75        internal bool hasBeenMovement = false;
 76
 77        internal bool isPanCameraActive = false;
 78        internal bool isMouseRightClickDown = false;
 79
 80        internal Coroutine smoothLookAtCoroutine;
 81        internal Coroutine smoothFocusOnTargetCoroutine;
 82        internal Coroutine smoothScrollCoroutine;
 83
 84        private InputAction_Hold.Started advanceForwardStartDelegate;
 85        private InputAction_Hold.Finished advanceForwardFinishedDelegate;
 86
 87        private InputAction_Hold.Started advanceBackStartDelegate;
 88        private InputAction_Hold.Finished advanceBackFinishedDelegate;
 89
 90        private InputAction_Hold.Started advanceLeftStartDelegate;
 91        private InputAction_Hold.Finished advanceLeftFinishedDelegate;
 92
 93        private InputAction_Hold.Started advanceRightStartDelegate;
 94        private InputAction_Hold.Finished advanceRightFinishedDelegate;
 95
 96        private InputAction_Hold.Started advanceDownStartDelegate;
 97        private InputAction_Hold.Finished advanceDownFinishedDelegate;
 98
 99        private InputAction_Hold.Started advanceUpStartDelegate;
 100        private InputAction_Hold.Finished advanceUpFinishedDelegate;
 101
 102        private InputAction_Hold.Started cameraPanStartDelegate;
 103        private InputAction_Hold.Finished cameraPanFinishedDelegate;
 104
 105        private InputAction_Trigger.Triggered zoomInFromKeyboardDelegate;
 106        private InputAction_Trigger.Triggered zoomOutFromKeyboardDelegate;
 107
 108        private Vector3 nextTranslation;
 109        internal Vector3 originalCameraPosition;
 110        internal Vector3 originalCameraPointToLookAt;
 623111        private Vector3 cameraVelocity = Vector3.zero;
 112
 113        private float lastMouseWheelTime;
 114        private float cameraPanAdvance;
 115        private float cameraLookAdvance;
 116        private bool isCameraDragging = false;
 117
 118        public bool invertMouseY = false;
 119
 120        private void Awake()
 121        {
 49122            BIWInputWrapper.OnMouseDrag += MouseDrag;
 49123            BIWInputWrapper.OnMouseDragRaw += MouseDragRaw;
 49124            BIWInputWrapper.OnMouseWheel += MouseWheel;
 125
 49126            BIWInputWrapper.OnMouseDown += OnInputMouseDown;
 49127            BIWInputWrapper.OnMouseUp += OnInputMouseUp;
 128
 49129            advanceForwardStartDelegate = (action) => isAdvancingForward = true;
 49130            advanceForwardFinishedDelegate = (action) => isAdvancingForward = false;
 131
 49132            if (advanceFowardInputAction != null)
 133            {
 36134                advanceFowardInputAction.OnStarted += advanceForwardStartDelegate;
 36135                advanceFowardInputAction.OnFinished += advanceForwardFinishedDelegate;
 136            }
 137
 49138            advanceBackStartDelegate = (action) => isAdvancingBackward = true;
 49139            advanceBackFinishedDelegate = (action) => isAdvancingBackward = false;
 140
 49141            if (advanceBackInputAction != null)
 142            {
 36143                advanceBackInputAction.OnStarted += advanceBackStartDelegate;
 36144                advanceBackInputAction.OnFinished += advanceBackFinishedDelegate;
 145            }
 146
 49147            advanceLeftStartDelegate = (action) => isAdvancingLeft = true;
 49148            advanceLeftFinishedDelegate = (action) => isAdvancingLeft = false;
 149
 49150            if (advanceLeftInputAction != null)
 151            {
 36152                advanceLeftInputAction.OnStarted += advanceLeftStartDelegate;
 36153                advanceLeftInputAction.OnFinished += advanceLeftFinishedDelegate;
 154            }
 155
 49156            advanceRightStartDelegate = (action) => isAdvancingRight = true;
 49157            advanceRightFinishedDelegate = (action) => isAdvancingRight = false;
 158
 49159            if (advanceRightInputAction != null)
 160            {
 36161                advanceRightInputAction.OnStarted += advanceRightStartDelegate;
 36162                advanceRightInputAction.OnFinished += advanceRightFinishedDelegate;
 163            }
 164
 49165            advanceUpStartDelegate = (action) => isAdvancingUp = true;
 49166            advanceUpFinishedDelegate = (action) => isAdvancingUp = false;
 167
 49168            if (advanceUpInputAction != null)
 169            {
 36170                advanceUpInputAction.OnStarted += advanceUpStartDelegate;
 36171                advanceUpInputAction.OnFinished += advanceUpFinishedDelegate;
 172            }
 173
 49174            advanceDownStartDelegate = (action) => isAdvancingDown = true;
 49175            advanceDownFinishedDelegate = (action) => isAdvancingDown = false;
 176
 49177            if (advanceDownInputAction != null)
 178            {
 36179                advanceDownInputAction.OnStarted += advanceDownStartDelegate;
 36180                advanceDownInputAction.OnFinished += advanceDownFinishedDelegate;
 181            }
 182
 49183            cameraPanStartDelegate = (action) => isPanCameraActive = true;
 49184            cameraPanFinishedDelegate = (action) =>
 185            {
 0186                isPanCameraActive = false;
 0187                isCameraDragging = false;
 0188            };
 189
 49190            if (cameraPanInputAction != null)
 191            {
 36192                cameraPanInputAction.OnStarted += cameraPanStartDelegate;
 36193                cameraPanInputAction.OnFinished += cameraPanFinishedDelegate;
 194            }
 195
 49196            zoomInFromKeyboardDelegate = (action) => MouseWheel(1f);
 197
 49198            if (zoomInFromKeyboardInputAction != null)
 36199                zoomInFromKeyboardInputAction.OnTriggered += zoomInFromKeyboardDelegate;
 200
 49201            zoomOutFromKeyboardDelegate = (action) => MouseWheel(-1f);
 202
 49203            if (zoomOutFromKeyboardInputAction != null)
 36204                zoomOutFromKeyboardInputAction.OnTriggered += zoomOutFromKeyboardDelegate;
 205
 49206            invertMouseY = Settings.i.generalSettings.Data.invertYAxis;
 207
 49208            Settings.i.generalSettings.OnChanged += UpdateLocalGeneralSettings;
 49209        }
 210
 211        private void UpdateLocalGeneralSettings(GeneralSettings obj)
 212        {
 0213            invertMouseY = obj.invertYAxis;
 0214        }
 215
 216        public void StartDetectingMovement()
 217        {
 0218            isDetectingMovement = true;
 0219            hasBeenMovement = false;
 0220        }
 221
 0222        public bool HasBeenMovement() { return hasBeenMovement; }
 223
 0224        public void StopDetectingMovement() { isDetectingMovement = false; }
 225
 226        internal void OnInputMouseUp(int buttonId, Vector3 mousePosition)
 227        {
 1228            if (buttonId == 1)
 1229                isMouseRightClickDown = false;
 0230            else if (buttonId == 2)
 0231                isCameraDragging = false;
 0232        }
 233
 234        internal void OnInputMouseDown(int buttonId, Vector3 mousePosition)
 235        {
 1236            if (buttonId != 1)
 0237                return;
 238
 1239            isMouseRightClickDown = true;
 1240            direction = Vector3.zero;
 1241        }
 242
 243        private void OnDestroy()
 244        {
 49245            BIWInputWrapper.OnMouseDrag -= MouseDrag;
 49246            BIWInputWrapper.OnMouseDragRaw -= MouseDragRaw;
 49247            BIWInputWrapper.OnMouseWheel -= MouseWheel;
 248
 49249            BIWInputWrapper.OnMouseDown -= OnInputMouseDown;
 49250            BIWInputWrapper.OnMouseUp -= OnInputMouseUp;
 251
 49252            if (advanceFowardInputAction != null)
 253            {
 36254                advanceFowardInputAction.OnStarted -= advanceForwardStartDelegate;
 36255                advanceFowardInputAction.OnFinished -= advanceForwardFinishedDelegate;
 256            }
 257
 49258            if (advanceBackInputAction != null)
 259            {
 36260                advanceBackInputAction.OnStarted -= advanceBackStartDelegate;
 36261                advanceBackInputAction.OnFinished -= advanceBackFinishedDelegate;
 262            }
 263
 49264            if (advanceLeftInputAction != null)
 265            {
 36266                advanceLeftInputAction.OnStarted -= advanceLeftStartDelegate;
 36267                advanceLeftInputAction.OnFinished -= advanceLeftFinishedDelegate;
 268            }
 269
 49270            if (advanceRightInputAction != null)
 271            {
 36272                advanceRightInputAction.OnStarted -= advanceRightStartDelegate;
 36273                advanceRightInputAction.OnFinished -= advanceRightFinishedDelegate;
 274            }
 275
 49276            if (advanceDownInputAction != null)
 277            {
 36278                advanceDownInputAction.OnStarted -= advanceDownStartDelegate;
 36279                advanceDownInputAction.OnFinished -= advanceDownFinishedDelegate;
 280            }
 281
 49282            if (advanceUpInputAction != null)
 283            {
 36284                advanceUpInputAction.OnStarted -= advanceUpStartDelegate;
 36285                advanceUpInputAction.OnFinished -= advanceUpFinishedDelegate;
 286            }
 287
 49288            if (cameraPanInputAction != null)
 289            {
 36290                cameraPanInputAction.OnStarted -= cameraPanStartDelegate;
 36291                cameraPanInputAction.OnFinished -= cameraPanFinishedDelegate;
 292            }
 293
 49294            if (zoomInFromKeyboardInputAction != null)
 36295                zoomInFromKeyboardInputAction.OnTriggered -= zoomInFromKeyboardDelegate;
 296
 49297            if (zoomOutFromKeyboardInputAction != null)
 36298                zoomOutFromKeyboardInputAction.OnTriggered -= zoomOutFromKeyboardDelegate;
 299
 49300            if (smoothScrollCoroutine != null)
 1301                CoroutineStarter.Stop(smoothScrollCoroutine);
 302
 49303            if (smoothLookAtCoroutine != null)
 1304                CoroutineStarter.Stop(smoothLookAtCoroutine);
 305
 49306            if (smoothFocusOnTargetCoroutine != null)
 1307                CoroutineStarter.Stop(smoothFocusOnTargetCoroutine);
 308
 49309            Settings.i.generalSettings.OnChanged -= UpdateLocalGeneralSettings;
 49310        }
 311
 312        private void Update()
 313        {
 88314            HandleCameraLook();
 88315            HandleCameraPan();
 88316            HandleCameraMovement();
 88317        }
 318
 319        #region CameraTransformChanges
 320
 321        private void HandleCameraMovement()
 322        {
 88323            HandleCameraMovementInput();
 88324            if (direction.magnitude >= CAMERA_MOVEMENT_DEACTIVATE_INPUT_MAGNITUD)
 0325                nextTranslation = direction;
 88326            nextTranslation = Vector3.Lerp(nextTranslation, Vector3.zero, lerpTime * Time.deltaTime);
 327
 88328            if (nextTranslation.magnitude >= CAMERA_MOVEMENT_THRESHOLD)
 0329                transform.Translate(nextTranslation * (movementSpeed * Time.deltaTime), Space.Self);
 88330        }
 331
 332        private void HandleCameraLook()
 333        {
 88334            Quaternion nextIteration =  Quaternion.Lerp(transform.rotation, Quaternion.Euler(new Vector3(pitch, yaw, 0f)
 335
 88336            if (Mathf.Abs(nextIteration.eulerAngles.magnitude - transform.rotation.eulerAngles.magnitude) >= CAMERA_ANGL
 0337                transform.rotation = nextIteration;
 88338        }
 339
 340        private void HandleCameraPan()
 341        {
 88342            panAxisX = Mathf.Lerp(panAxisX, 0, cameraPanAdvance * Time.deltaTime);
 88343            panAxisY = Mathf.Lerp(panAxisY, 0, cameraPanAdvance * Time.deltaTime);
 344
 88345            if (Mathf.Abs(panAxisX) >= CAMERA_PAN_THRESHOLD || Mathf.Abs(panAxisY) >= CAMERA_PAN_THRESHOLD)
 0346                transform.Translate(panAxisX, panAxisY, 0);
 88347        }
 348
 349        #endregion
 350
 351        internal void HandleCameraMovementInput()
 352        {
 90353            int velocityChangedCount = 0;
 90354            if (isAdvancingForward)
 355            {
 1356                cameraVelocity += GetTotalVelocity(Vector3.forward);
 1357                velocityChangedCount++;
 358            }
 359
 90360            if (isAdvancingBackward)
 361            {
 1362                cameraVelocity += GetTotalVelocity(Vector3.back);
 1363                velocityChangedCount++;
 364            }
 365
 90366            if (!isAdvancingBackward && !isAdvancingForward)
 88367                cameraVelocity.z = Mathf.Lerp(cameraVelocity.z, 0, lerpDeccelerationTime);
 368
 90369            if (isAdvancingRight)
 370            {
 1371                cameraVelocity += GetTotalVelocity(Vector3.right) * xPlaneSpeedPercentCompensantion;
 1372                velocityChangedCount++;
 373            }
 374
 90375            if (isAdvancingLeft)
 376            {
 1377                cameraVelocity += GetTotalVelocity(Vector3.left) * xPlaneSpeedPercentCompensantion;
 1378                velocityChangedCount++;
 379            }
 380
 90381            if (!isAdvancingRight && !isAdvancingLeft)
 88382                cameraVelocity.x = Mathf.Lerp(cameraVelocity.x, 0, lerpDeccelerationTime);
 383
 90384            if (isAdvancingUp)
 385            {
 1386                cameraVelocity += GetTotalVelocity(Vector3.up);
 1387                velocityChangedCount++;
 388            }
 389
 90390            if (isAdvancingDown)
 391            {
 1392                cameraVelocity += GetTotalVelocity(Vector3.down);
 1393                velocityChangedCount++;
 394            }
 395
 90396            if (!isAdvancingUp && !isAdvancingDown)
 88397                cameraVelocity.y = Mathf.Lerp(cameraVelocity.y, 0, lerpDeccelerationTime);
 398
 90399            if (velocityChangedCount != 0)
 2400                cameraVelocity = Vector3.ClampMagnitude(cameraVelocity, speedClamp);
 401
 90402            direction = cameraVelocity;
 90403        }
 404
 405        private Vector3 GetTotalVelocity(Vector3 velocityToAdd)
 406        {
 6407            if (!isMouseRightClickDown)
 0408                return  Vector3.zero;
 409
 6410            if (isDetectingMovement)
 0411                hasBeenMovement = true;
 6412            return velocityToAdd * (initalAcceleration * Time.deltaTime);
 413        }
 414
 0415        public void SetCameraCanMove(bool canMove) { isCameraAbleToMove = canMove; }
 416
 417        internal void MouseWheel(float axis)
 418        {
 1419            if (!isCameraAbleToMove || isCameraDragging)
 0420                return;
 421
 1422            if (smoothScrollCoroutine != null)
 0423                CoroutineStarter.Stop(smoothScrollCoroutine);
 424
 1425            float delta = Time.time - lastMouseWheelTime;
 1426            float scrollValue = axis * Mathf.Clamp01(delta);
 1427            lastMouseWheelTime = Time.time;
 428
 1429            smoothScrollCoroutine = CoroutineStarter.Start(SmoothScroll(scrollValue));
 1430        }
 431
 432        internal void MouseDragRaw(int buttonId, Vector3 mousePosition, float axisX, float axisY)
 433        {
 1434            if (buttonId == 1 && !isPanCameraActive)
 1435                CameraLook(axisX, axisY);
 1436        }
 437
 438        internal void MouseDrag(int buttonId, Vector3 mousePosition, float axisX, float axisY)
 439        {
 1440            if (buttonId == 2 || buttonId == 1 && isPanCameraActive)
 1441                CameraDrag(axisX, axisY);
 1442        }
 443
 444        private void CameraDrag(float axisX, float axisY)
 445        {
 1446            if (!isCameraAbleToMove)
 0447                return;
 448
 1449            panAxisX += -axisX * Time.deltaTime * dragSpeed;
 1450            panAxisY += -axisY * Time.deltaTime * dragSpeed;
 1451            cameraPanAdvance = smoothCameraPanAceleration;
 1452            isCameraDragging = true;
 1453        }
 454
 455        private void CameraLook(float axisX, float axisY)
 456        {
 1457            if (!isCameraAbleToMove || !isMouseRightClickDown)
 0458                return;
 459
 1460            yaw += lookSpeedH * axisX;
 1461            if (invertMouseY)
 462            {
 0463                pitch -= lookSpeedV * -axisY;
 0464            }
 465            else {
 1466                pitch -= lookSpeedV * axisY;
 467            }
 1468            cameraLookAdvance = smoothCameraLookSpeed * Time.deltaTime;
 1469        }
 470
 1471        public override Vector3 OnGetRotation() { return transform.eulerAngles; }
 472
 0473        public Vector3 GetCameraPosition => defaultVirtualCamera.transform.position;
 0474        public Vector3 GetCameraFoward => defaultVirtualCamera.transform.forward;
 475
 476        public void FocusOnEntities(List<BIWEntity> entitiesToFocus)
 477        {
 1478            if (entitiesToFocus.Count <= 0)
 0479                return;
 480
 1481            Vector3 middlePoint = FindMidPoint(entitiesToFocus);
 1482            if (Vector3.positiveInfinity == middlePoint ||
 483                Vector3.negativeInfinity == middlePoint ||
 484                float.IsNaN(middlePoint.x) ||
 485                float.IsNaN(middlePoint.y) ||
 486                float.IsNaN(middlePoint.z))
 0487                return;
 488
 1489            if (smoothFocusOnTargetCoroutine != null)
 0490                CoroutineStarter.Stop(smoothFocusOnTargetCoroutine);
 1491            smoothFocusOnTargetCoroutine = CoroutineStarter.Start(SmoothFocusOnTarget(middlePoint));
 1492            SmoothLookAt(middlePoint);
 1493        }
 494
 2495        public void SetPosition(Vector3 position) { transform.position = position; }
 496
 74497        public void LookAt(Transform transformToLookAt) { LookAt(transformToLookAt.position); }
 498
 499        public void LookAt(Vector3 pointToLookAt)
 500        {
 38501            transform.LookAt(pointToLookAt);
 38502            yaw = transform.eulerAngles.y;
 38503            pitch = transform.eulerAngles.x;
 38504        }
 505
 0506        public void SmoothLookAt(Transform transformToLookAt) { SmoothLookAt(transformToLookAt.position); }
 507
 508        public void SmoothLookAt(Vector3 position)
 509        {
 1510            if (smoothLookAtCoroutine != null)
 0511                CoroutineStarter.Stop(smoothLookAtCoroutine);
 1512            smoothLookAtCoroutine = CoroutineStarter.Start(SmoothLookAtCorutine(position));
 1513        }
 514
 515        Vector3 FindMidPoint(List<BIWEntity> entitiesToLook)
 516        {
 1517            Vector3 finalPosition = Vector3.zero;
 1518            int totalPoints = 0;
 4519            foreach (BIWEntity entity in entitiesToLook)
 520            {
 1521                if (entity.rootEntity.meshRootGameObject && entity.rootEntity.meshesInfo.renderers.Length > 0)
 522                {
 1523                    Vector3 midPointFromEntity = Vector3.zero;
 4524                    foreach (Renderer render in entity.rootEntity.renderers)
 525                    {
 1526                        if (render == null)
 527                            continue;
 1528                        midPointFromEntity += render.bounds.center;
 529                    }
 530
 1531                    midPointFromEntity /= entity.rootEntity.renderers.Length;
 1532                    finalPosition += midPointFromEntity;
 1533                    totalPoints++;
 534                }
 535            }
 536
 1537            finalPosition /= totalPoints;
 1538            return finalPosition;
 539        }
 540
 541        IEnumerator SmoothScroll(float axis)
 542        {
 1543            float scrollMovementDestination = axis * zoomSpeed;
 544
 1545            Vector3 targetPosition = transform.position + transform.TransformDirection(Vector3.forward * scrollMovementD
 546
 1547            float advance = 0;
 1548            while (advance <= 1)
 549            {
 1550                advance += smoothLookAtSpeed * Time.deltaTime;
 1551                Vector3 result = Vector3.Lerp(transform.position, targetPosition, advance);
 1552                transform.position = result;
 1553                yield return null;
 554            }
 0555        }
 556
 557        IEnumerator SmoothFocusOnTarget(Vector3 targetPosition)
 558        {
 1559            float advance = 0;
 17560            while (advance <= 1)
 561            {
 17562                advance += smoothLookAtSpeed * Time.deltaTime;
 17563                transform.position = Vector3.Lerp(transform.position, targetPosition, advance);
 17564                if (Vector3.Distance(transform.position, targetPosition) <= focusDistance)
 1565                    yield break;
 16566                yield return null;
 567            }
 0568        }
 569
 570        IEnumerator SmoothLookAtCorutine(Vector3 targetPosition)
 571        {
 1572            Quaternion targetRotation = Quaternion.LookRotation(targetPosition - transform.position);
 1573            float advance = 0;
 23574            while (advance <= 1)
 575            {
 23576                advance += smoothLookAtSpeed * Time.deltaTime;
 23577                transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, advance);
 23578                yield return null;
 579            }
 580
 0581            yaw = transform.eulerAngles.y;
 0582            pitch = transform.eulerAngles.x;
 0583        }
 584
 78585        public void SetResetConfiguration(Vector3 position, Transform lookAt) { SetResetConfiguration(position, lookAt.p
 586
 587        public void SetResetConfiguration(Vector3 position, Vector3 pointToLook)
 588        {
 0589            originalCameraPosition = position;
 0590            originalCameraPointToLookAt = pointToLook;
 0591        }
 592
 593        public void ResetCameraPosition()
 594        {
 1595            SetPosition(originalCameraPosition);
 1596            LookAt(originalCameraPointToLookAt);
 1597            direction = Vector3.zero;
 1598        }
 599    }
 600}