< 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:142
Uncovered lines:138
Coverable lines:280
Total lines:600
Line coverage:50.7% (142 of 280)
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%12300%
OnInputMouseDown(...)0%6200%
OnDestroy()0%13.0813092.11%
Update()0%110100%
HandleCameraMovement()0%3.213071.43%
HandleCameraLook()0%2.062075%
HandleCameraPan()0%3.073080%
HandleCameraMovementInput()0%31.6614055.17%
GetTotalVelocity(...)0%12300%
SetCameraCanMove(...)0%2100%
MouseWheel(...)0%20400%
MouseDragRaw(...)0%12300%
MouseDrag(...)0%20400%
CameraDrag(...)0%6200%
CameraLook(...)0%20400%
OnGetRotation()0%2100%
FocusOnEntities(...)0%72800%
SetPosition(...)0%2100%
LookAt(...)0%110100%
LookAt(...)0%110100%
SmoothLookAt(...)0%2100%
SmoothLookAt(...)0%6200%
FindMidPoint(...)0%42600%
SmoothScroll()0%20400%
SmoothFocusOnTarget()0%30500%
SmoothLookAtCorutine()0%20400%
SetResetConfiguration(...)0%110100%
SetResetConfiguration(...)0%110100%
ResetCameraPosition()0%2100%

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
 49218        public float focusDistance = 5f;
 19
 20        [Header("Camera Movement")]
 49221        public float xPlaneSpeedPercentCompensantion = 0.85f;
 22
 49223        public float movementSpeed = 5f;
 49224        public float lerpTime = 0.3F;
 25
 49226        public float lerpDeccelerationTime = 0.3F;
 49227        public float initalAcceleration = 2f;
 49228        public float speedClamp = 1f;
 29
 30        [Header("Camera Look")]
 49231        public float smoothLookAtSpeed = 5f;
 32
 49233        public float smoothCameraLookSpeed = 5f;
 49234        public float lookSpeedH = 2f;
 49235        public float lookSpeedV = 2f;
 36
 37        [Header("Camera Pan")]
 49238        public float smoothCameraPanAceleration = 5f;
 39
 49240        public float dragSpeed = 3f;
 41
 42        [Header("Camera Zoom")]
 49243        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
 49257        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
 49265        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;
 492111        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        {
 32122            BIWInputWrapper.OnMouseDrag += MouseDrag;
 32123            BIWInputWrapper.OnMouseDragRaw += MouseDragRaw;
 32124            BIWInputWrapper.OnMouseWheel += MouseWheel;
 125
 32126            BIWInputWrapper.OnMouseDown += OnInputMouseDown;
 32127            BIWInputWrapper.OnMouseUp += OnInputMouseUp;
 128
 32129            advanceForwardStartDelegate = (action) => isAdvancingForward = true;
 32130            advanceForwardFinishedDelegate = (action) => isAdvancingForward = false;
 131
 32132            if (advanceFowardInputAction != null)
 133            {
 32134                advanceFowardInputAction.OnStarted += advanceForwardStartDelegate;
 32135                advanceFowardInputAction.OnFinished += advanceForwardFinishedDelegate;
 136            }
 137
 32138            advanceBackStartDelegate = (action) => isAdvancingBackward = true;
 32139            advanceBackFinishedDelegate = (action) => isAdvancingBackward = false;
 140
 32141            if (advanceBackInputAction != null)
 142            {
 32143                advanceBackInputAction.OnStarted += advanceBackStartDelegate;
 32144                advanceBackInputAction.OnFinished += advanceBackFinishedDelegate;
 145            }
 146
 32147            advanceLeftStartDelegate = (action) => isAdvancingLeft = true;
 32148            advanceLeftFinishedDelegate = (action) => isAdvancingLeft = false;
 149
 32150            if (advanceLeftInputAction != null)
 151            {
 32152                advanceLeftInputAction.OnStarted += advanceLeftStartDelegate;
 32153                advanceLeftInputAction.OnFinished += advanceLeftFinishedDelegate;
 154            }
 155
 32156            advanceRightStartDelegate = (action) => isAdvancingRight = true;
 32157            advanceRightFinishedDelegate = (action) => isAdvancingRight = false;
 158
 32159            if (advanceRightInputAction != null)
 160            {
 32161                advanceRightInputAction.OnStarted += advanceRightStartDelegate;
 32162                advanceRightInputAction.OnFinished += advanceRightFinishedDelegate;
 163            }
 164
 32165            advanceUpStartDelegate = (action) => isAdvancingUp = true;
 32166            advanceUpFinishedDelegate = (action) => isAdvancingUp = false;
 167
 32168            if (advanceUpInputAction != null)
 169            {
 32170                advanceUpInputAction.OnStarted += advanceUpStartDelegate;
 32171                advanceUpInputAction.OnFinished += advanceUpFinishedDelegate;
 172            }
 173
 32174            advanceDownStartDelegate = (action) => isAdvancingDown = true;
 32175            advanceDownFinishedDelegate = (action) => isAdvancingDown = false;
 176
 32177            if (advanceDownInputAction != null)
 178            {
 32179                advanceDownInputAction.OnStarted += advanceDownStartDelegate;
 32180                advanceDownInputAction.OnFinished += advanceDownFinishedDelegate;
 181            }
 182
 32183            cameraPanStartDelegate = (action) => isPanCameraActive = true;
 32184            cameraPanFinishedDelegate = (action) =>
 185            {
 0186                isPanCameraActive = false;
 0187                isCameraDragging = false;
 0188            };
 189
 32190            if (cameraPanInputAction != null)
 191            {
 32192                cameraPanInputAction.OnStarted += cameraPanStartDelegate;
 32193                cameraPanInputAction.OnFinished += cameraPanFinishedDelegate;
 194            }
 195
 32196            zoomInFromKeyboardDelegate = (action) => MouseWheel(1f);
 197
 32198            if (zoomInFromKeyboardInputAction != null)
 32199                zoomInFromKeyboardInputAction.OnTriggered += zoomInFromKeyboardDelegate;
 200
 32201            zoomOutFromKeyboardDelegate = (action) => MouseWheel(-1f);
 202
 32203            if (zoomOutFromKeyboardInputAction != null)
 32204                zoomOutFromKeyboardInputAction.OnTriggered += zoomOutFromKeyboardDelegate;
 205
 32206            invertMouseY = Settings.i.generalSettings.Data.invertYAxis;
 207
 32208            Settings.i.generalSettings.OnChanged += UpdateLocalGeneralSettings;
 32209        }
 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        {
 0228            if (buttonId == 1)
 0229                isMouseRightClickDown = false;
 0230            else if (buttonId == 2)
 0231                isCameraDragging = false;
 0232        }
 233
 234        internal void OnInputMouseDown(int buttonId, Vector3 mousePosition)
 235        {
 0236            if (buttonId != 1)
 0237                return;
 238
 0239            isMouseRightClickDown = true;
 0240            direction = Vector3.zero;
 0241        }
 242
 243        private void OnDestroy()
 244        {
 32245            BIWInputWrapper.OnMouseDrag -= MouseDrag;
 32246            BIWInputWrapper.OnMouseDragRaw -= MouseDragRaw;
 32247            BIWInputWrapper.OnMouseWheel -= MouseWheel;
 248
 32249            BIWInputWrapper.OnMouseDown -= OnInputMouseDown;
 32250            BIWInputWrapper.OnMouseUp -= OnInputMouseUp;
 251
 32252            if (advanceFowardInputAction != null)
 253            {
 32254                advanceFowardInputAction.OnStarted -= advanceForwardStartDelegate;
 32255                advanceFowardInputAction.OnFinished -= advanceForwardFinishedDelegate;
 256            }
 257
 32258            if (advanceBackInputAction != null)
 259            {
 32260                advanceBackInputAction.OnStarted -= advanceBackStartDelegate;
 32261                advanceBackInputAction.OnFinished -= advanceBackFinishedDelegate;
 262            }
 263
 32264            if (advanceLeftInputAction != null)
 265            {
 32266                advanceLeftInputAction.OnStarted -= advanceLeftStartDelegate;
 32267                advanceLeftInputAction.OnFinished -= advanceLeftFinishedDelegate;
 268            }
 269
 32270            if (advanceRightInputAction != null)
 271            {
 32272                advanceRightInputAction.OnStarted -= advanceRightStartDelegate;
 32273                advanceRightInputAction.OnFinished -= advanceRightFinishedDelegate;
 274            }
 275
 32276            if (advanceDownInputAction != null)
 277            {
 32278                advanceDownInputAction.OnStarted -= advanceDownStartDelegate;
 32279                advanceDownInputAction.OnFinished -= advanceDownFinishedDelegate;
 280            }
 281
 32282            if (advanceUpInputAction != null)
 283            {
 32284                advanceUpInputAction.OnStarted -= advanceUpStartDelegate;
 32285                advanceUpInputAction.OnFinished -= advanceUpFinishedDelegate;
 286            }
 287
 32288            if (cameraPanInputAction != null)
 289            {
 32290                cameraPanInputAction.OnStarted -= cameraPanStartDelegate;
 32291                cameraPanInputAction.OnFinished -= cameraPanFinishedDelegate;
 292            }
 293
 32294            if (zoomInFromKeyboardInputAction != null)
 32295                zoomInFromKeyboardInputAction.OnTriggered -= zoomInFromKeyboardDelegate;
 296
 32297            if (zoomOutFromKeyboardInputAction != null)
 32298                zoomOutFromKeyboardInputAction.OnTriggered -= zoomOutFromKeyboardDelegate;
 299
 32300            if (smoothScrollCoroutine != null)
 0301                CoroutineStarter.Stop(smoothScrollCoroutine);
 302
 32303            if (smoothLookAtCoroutine != null)
 0304                CoroutineStarter.Stop(smoothLookAtCoroutine);
 305
 32306            if (smoothFocusOnTargetCoroutine != null)
 0307                CoroutineStarter.Stop(smoothFocusOnTargetCoroutine);
 308
 32309            Settings.i.generalSettings.OnChanged -= UpdateLocalGeneralSettings;
 32310        }
 311
 312        private void Update()
 313        {
 58314            HandleCameraLook();
 58315            HandleCameraPan();
 58316            HandleCameraMovement();
 58317        }
 318
 319        #region CameraTransformChanges
 320
 321        private void HandleCameraMovement()
 322        {
 58323            HandleCameraMovementInput();
 58324            if (direction.magnitude >= CAMERA_MOVEMENT_DEACTIVATE_INPUT_MAGNITUD)
 0325                nextTranslation = direction;
 58326            nextTranslation = Vector3.Lerp(nextTranslation, Vector3.zero, lerpTime * Time.deltaTime);
 327
 58328            if (nextTranslation.magnitude >= CAMERA_MOVEMENT_THRESHOLD)
 0329                transform.Translate(nextTranslation * (movementSpeed * Time.deltaTime), Space.Self);
 58330        }
 331
 332        private void HandleCameraLook()
 333        {
 58334            Quaternion nextIteration =  Quaternion.Lerp(transform.rotation, Quaternion.Euler(new Vector3(pitch, yaw, 0f)
 335
 58336            if (Mathf.Abs(nextIteration.eulerAngles.magnitude - transform.rotation.eulerAngles.magnitude) >= CAMERA_ANGL
 0337                transform.rotation = nextIteration;
 58338        }
 339
 340        private void HandleCameraPan()
 341        {
 58342            panAxisX = Mathf.Lerp(panAxisX, 0, cameraPanAdvance * Time.deltaTime);
 58343            panAxisY = Mathf.Lerp(panAxisY, 0, cameraPanAdvance * Time.deltaTime);
 344
 58345            if (Mathf.Abs(panAxisX) >= CAMERA_PAN_THRESHOLD || Mathf.Abs(panAxisY) >= CAMERA_PAN_THRESHOLD)
 0346                transform.Translate(panAxisX, panAxisY, 0);
 58347        }
 348
 349        #endregion
 350
 351        internal void HandleCameraMovementInput()
 352        {
 58353            int velocityChangedCount = 0;
 58354            if (isAdvancingForward)
 355            {
 0356                cameraVelocity += GetTotalVelocity(Vector3.forward);
 0357                velocityChangedCount++;
 358            }
 359
 58360            if (isAdvancingBackward)
 361            {
 0362                cameraVelocity += GetTotalVelocity(Vector3.back);
 0363                velocityChangedCount++;
 364            }
 365
 58366            if (!isAdvancingBackward && !isAdvancingForward)
 58367                cameraVelocity.z = Mathf.Lerp(cameraVelocity.z, 0, lerpDeccelerationTime);
 368
 58369            if (isAdvancingRight)
 370            {
 0371                cameraVelocity += GetTotalVelocity(Vector3.right) * xPlaneSpeedPercentCompensantion;
 0372                velocityChangedCount++;
 373            }
 374
 58375            if (isAdvancingLeft)
 376            {
 0377                cameraVelocity += GetTotalVelocity(Vector3.left) * xPlaneSpeedPercentCompensantion;
 0378                velocityChangedCount++;
 379            }
 380
 58381            if (!isAdvancingRight && !isAdvancingLeft)
 58382                cameraVelocity.x = Mathf.Lerp(cameraVelocity.x, 0, lerpDeccelerationTime);
 383
 58384            if (isAdvancingUp)
 385            {
 0386                cameraVelocity += GetTotalVelocity(Vector3.up);
 0387                velocityChangedCount++;
 388            }
 389
 58390            if (isAdvancingDown)
 391            {
 0392                cameraVelocity += GetTotalVelocity(Vector3.down);
 0393                velocityChangedCount++;
 394            }
 395
 58396            if (!isAdvancingUp && !isAdvancingDown)
 58397                cameraVelocity.y = Mathf.Lerp(cameraVelocity.y, 0, lerpDeccelerationTime);
 398
 58399            if (velocityChangedCount != 0)
 0400                cameraVelocity = Vector3.ClampMagnitude(cameraVelocity, speedClamp);
 401
 58402            direction = cameraVelocity;
 58403        }
 404
 405        private Vector3 GetTotalVelocity(Vector3 velocityToAdd)
 406        {
 0407            if (!isMouseRightClickDown)
 0408                return  Vector3.zero;
 409
 0410            if (isDetectingMovement)
 0411                hasBeenMovement = true;
 0412            return velocityToAdd * (initalAcceleration * Time.deltaTime);
 413        }
 414
 0415        public void SetCameraCanMove(bool canMove) { isCameraAbleToMove = canMove; }
 416
 417        internal void MouseWheel(float axis)
 418        {
 0419            if (!isCameraAbleToMove || isCameraDragging)
 0420                return;
 421
 0422            if (smoothScrollCoroutine != null)
 0423                CoroutineStarter.Stop(smoothScrollCoroutine);
 424
 0425            float delta = Time.time - lastMouseWheelTime;
 0426            float scrollValue = axis * Mathf.Clamp01(delta);
 0427            lastMouseWheelTime = Time.time;
 428
 0429            smoothScrollCoroutine = CoroutineStarter.Start(SmoothScroll(scrollValue));
 0430        }
 431
 432        internal void MouseDragRaw(int buttonId, Vector3 mousePosition, float axisX, float axisY)
 433        {
 0434            if (buttonId == 1 && !isPanCameraActive)
 0435                CameraLook(axisX, axisY);
 0436        }
 437
 438        internal void MouseDrag(int buttonId, Vector3 mousePosition, float axisX, float axisY)
 439        {
 0440            if (buttonId == 2 || buttonId == 1 && isPanCameraActive)
 0441                CameraDrag(axisX, axisY);
 0442        }
 443
 444        private void CameraDrag(float axisX, float axisY)
 445        {
 0446            if (!isCameraAbleToMove)
 0447                return;
 448
 0449            panAxisX += -axisX * Time.deltaTime * dragSpeed;
 0450            panAxisY += -axisY * Time.deltaTime * dragSpeed;
 0451            cameraPanAdvance = smoothCameraPanAceleration;
 0452            isCameraDragging = true;
 0453        }
 454
 455        private void CameraLook(float axisX, float axisY)
 456        {
 0457            if (!isCameraAbleToMove || !isMouseRightClickDown)
 0458                return;
 459
 0460            yaw += lookSpeedH * axisX;
 0461            if (invertMouseY)
 462            {
 0463                pitch -= lookSpeedV * -axisY;
 464            }
 465            else {
 0466                pitch -= lookSpeedV * axisY;
 467            }
 0468            cameraLookAdvance = smoothCameraLookSpeed * Time.deltaTime;
 0469        }
 470
 0471        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        {
 0478            if (entitiesToFocus.Count <= 0)
 0479                return;
 480
 0481            Vector3 middlePoint = FindMidPoint(entitiesToFocus);
 0482            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
 0489            if (smoothFocusOnTargetCoroutine != null)
 0490                CoroutineStarter.Stop(smoothFocusOnTargetCoroutine);
 0491            smoothFocusOnTargetCoroutine = CoroutineStarter.Start(SmoothFocusOnTarget(middlePoint));
 0492            SmoothLookAt(middlePoint);
 0493        }
 494
 0495        public void SetPosition(Vector3 position) { transform.position = position; }
 496
 64497        public void LookAt(Transform transformToLookAt) { LookAt(transformToLookAt.position); }
 498
 499        public void LookAt(Vector3 pointToLookAt)
 500        {
 32501            transform.LookAt(pointToLookAt);
 32502            yaw = transform.eulerAngles.y;
 32503            pitch = transform.eulerAngles.x;
 32504        }
 505
 0506        public void SmoothLookAt(Transform transformToLookAt) { SmoothLookAt(transformToLookAt.position); }
 507
 508        public void SmoothLookAt(Vector3 position)
 509        {
 0510            if (smoothLookAtCoroutine != null)
 0511                CoroutineStarter.Stop(smoothLookAtCoroutine);
 0512            smoothLookAtCoroutine = CoroutineStarter.Start(SmoothLookAtCorutine(position));
 0513        }
 514
 515        Vector3 FindMidPoint(List<BIWEntity> entitiesToLook)
 516        {
 0517            Vector3 finalPosition = Vector3.zero;
 0518            int totalPoints = 0;
 0519            foreach (BIWEntity entity in entitiesToLook)
 520            {
 0521                if (entity.rootEntity.meshRootGameObject && entity.rootEntity.meshesInfo.renderers.Length > 0)
 522                {
 0523                    Vector3 midPointFromEntity = Vector3.zero;
 0524                    foreach (Renderer render in entity.rootEntity.renderers)
 525                    {
 0526                        if (render == null)
 527                            continue;
 0528                        midPointFromEntity += render.bounds.center;
 529                    }
 530
 0531                    midPointFromEntity /= entity.rootEntity.renderers.Length;
 0532                    finalPosition += midPointFromEntity;
 0533                    totalPoints++;
 534                }
 535            }
 536
 0537            finalPosition /= totalPoints;
 0538            return finalPosition;
 539        }
 540
 541        IEnumerator SmoothScroll(float axis)
 542        {
 0543            float scrollMovementDestination = axis * zoomSpeed;
 544
 0545            Vector3 targetPosition = transform.position + transform.TransformDirection(Vector3.forward * scrollMovementD
 546
 0547            float advance = 0;
 0548            while (advance <= 1)
 549            {
 0550                advance += smoothLookAtSpeed * Time.deltaTime;
 0551                Vector3 result = Vector3.Lerp(transform.position, targetPosition, advance);
 0552                transform.position = result;
 0553                yield return null;
 554            }
 0555        }
 556
 557        IEnumerator SmoothFocusOnTarget(Vector3 targetPosition)
 558        {
 0559            float advance = 0;
 0560            while (advance <= 1)
 561            {
 0562                advance += smoothLookAtSpeed * Time.deltaTime;
 0563                transform.position = Vector3.Lerp(transform.position, targetPosition, advance);
 0564                if (Vector3.Distance(transform.position, targetPosition) <= focusDistance)
 0565                    yield break;
 0566                yield return null;
 567            }
 0568        }
 569
 570        IEnumerator SmoothLookAtCorutine(Vector3 targetPosition)
 571        {
 0572            Quaternion targetRotation = Quaternion.LookRotation(targetPosition - transform.position);
 0573            float advance = 0;
 0574            while (advance <= 1)
 575            {
 0576                advance += smoothLookAtSpeed * Time.deltaTime;
 0577                transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, advance);
 0578                yield return null;
 579            }
 580
 0581            yaw = transform.eulerAngles.y;
 0582            pitch = transform.eulerAngles.x;
 0583        }
 584
 64585        public void SetResetConfiguration(Vector3 position, Transform lookAt) { SetResetConfiguration(position, lookAt.p
 586
 587        public void SetResetConfiguration(Vector3 position, Vector3 pointToLook)
 588        {
 32589            originalCameraPosition = position;
 32590            originalCameraPointToLookAt = pointToLook;
 32591        }
 592
 593        public void ResetCameraPosition()
 594        {
 0595            SetPosition(originalCameraPosition);
 0596            LookAt(originalCameraPointToLookAt);
 0597            direction = Vector3.zero;
 0598        }
 599    }
 600}