< Summary

Class:MainScripts.DCL.Controllers.HUD.CharacterPreview.PreviewCameraZoomController
Assembly:CharacterPreviewController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/CharacterPreview/PreviewCameraZoomController.cs
Covered lines:0
Uncovered lines:25
Coverable lines:25
Total lines:72
Line coverage:0% (0 of 25)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:6
Method coverage:0% (0 of 6)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PreviewCameraZoomController()0%2100%
Configure(...)0%2100%
OnPointerEnter(...)0%2100%
OnPointerExit(...)0%2100%
ZoomAsync()0%42600%
Dispose()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/CharacterPreview/PreviewCameraZoomController.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL.Tasks;
 3using System;
 4using System.Threading;
 5using UnityEngine;
 6using UnityEngine.EventSystems;
 7
 8namespace MainScripts.DCL.Controllers.HUD.CharacterPreview
 9{
 10    public class PreviewCameraZoomController : IPreviewCameraZoomController
 11    {
 12        public event Action<Vector3> OnZoom;
 13
 14        private InputAction_Measurable mouseWheelAction;
 15        private float zoomSpeed;
 16        private float smoothTime;
 17        private ICharacterPreviewInputDetector characterPreviewInputDetector;
 18        private Vector3 currentZoomDelta;
 19        private Vector3 currentZoomVelocity;
 020        private CancellationTokenSource cts = new ();
 21
 22        public void Configure(
 23            InputAction_Measurable mouseWheelAction,
 24            float zoomSpeed,
 25            float smoothTime,
 26            ICharacterPreviewInputDetector characterPreviewInputDetector)
 27        {
 028            this.mouseWheelAction = mouseWheelAction;
 029            this.zoomSpeed = zoomSpeed;
 030            this.smoothTime = smoothTime;
 031            this.characterPreviewInputDetector = characterPreviewInputDetector;
 32
 033            characterPreviewInputDetector.OnPointerFocus += OnPointerEnter;
 034            characterPreviewInputDetector.OnPointerUnFocus += OnPointerExit;
 035        }
 36
 37        private void OnPointerEnter(PointerEventData eventData)
 38        {
 039            cts = cts.SafeRestart();
 040            ZoomAsync(cts.Token).Forget();
 041        }
 42
 43        private void OnPointerExit(PointerEventData eventData)
 44        {
 045            cts = cts.SafeRestart();
 046            currentZoomDelta = Vector3.zero;
 047        }
 48
 49        private async UniTask ZoomAsync(CancellationToken ct)
 50        {
 051            while (!ct.IsCancellationRequested)
 52            {
 053                Vector3 newZoomDelta = Vector3.forward * (-mouseWheelAction.GetValue() * zoomSpeed);
 54
 055                if (currentZoomDelta != newZoomDelta)
 56                {
 057                    currentZoomDelta = Vector3.SmoothDamp(currentZoomDelta, newZoomDelta, ref currentZoomVelocity, smoot
 058                    OnZoom?.Invoke(currentZoomDelta);
 59                }
 60
 061                await UniTask.NextFrame(ct);
 62            }
 063        }
 64
 65        public void Dispose()
 66        {
 067            cts.SafeCancelAndDispose();
 068            characterPreviewInputDetector.OnPointerFocus -= OnPointerEnter;
 069            characterPreviewInputDetector.OnPointerUnFocus -= OnPointerExit;
 070        }
 71    }
 72}