< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PreviewCameraRotation()0%110100%
OnBeginDrag(...)0%2100%
OnDrag(...)0%12300%
OnEndDrag(...)0%12300%
SlowDown()0%30500%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections;
 3using UnityEngine;
 4using UnityEngine.EventSystems;
 5
 6namespace MainScripts.DCL.Controllers.HUD.CharacterPreview
 7{
 8    public class PreviewCameraRotation : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
 9    {
 10        public event System.Action<float> OnHorizontalRotation;
 11        public event System.Action<double> OnEndDragEvent;
 12
 5213        public float rotationFactor = -15f;
 14
 5215        public float slowDownTime = 0.5f;
 16
 17        private float currentHorizontalRotationVelocity = 0f;
 18
 19        private float slowDownVelocity;
 20
 21        private Coroutine slowDownCoroutine;
 22
 23        private float timer;
 24        private DateTime startDragDateTime;
 25
 26        public void OnBeginDrag(PointerEventData eventData)
 27        {
 028            startDragDateTime = DateTime.Now;
 029            AudioScriptableObjects.buttonClick.Play(true);
 030        }
 31
 32        public void OnDrag(PointerEventData eventData)
 33        {
 034            if (slowDownCoroutine != null)
 35            {
 036                StopCoroutine(slowDownCoroutine);
 037                slowDownCoroutine = null;
 38            }
 39
 040            currentHorizontalRotationVelocity = rotationFactor * eventData.delta.x;
 041            OnHorizontalRotation?.Invoke(currentHorizontalRotationVelocity);
 042        }
 43
 44        public void OnEndDrag(PointerEventData eventData)
 45        {
 046            timer = slowDownTime;
 047            slowDownVelocity = currentHorizontalRotationVelocity;
 48
 049            if (slowDownCoroutine == null)
 50            {
 051                slowDownCoroutine = StartCoroutine(SlowDown());
 52            }
 53
 054            OnEndDragEvent?.Invoke((DateTime.Now - startDragDateTime).TotalMilliseconds);
 055            AudioScriptableObjects.buttonRelease.Play(true);
 056        }
 57
 58        private IEnumerator SlowDown()
 59        {
 060            float inverseTimer = 1f / slowDownTime;
 61
 062            while (timer > 0)
 63            {
 064                timer -= Time.deltaTime;
 065                currentHorizontalRotationVelocity  = Mathf.Lerp(slowDownVelocity, 0, 1 - (timer * inverseTimer));
 066                OnHorizontalRotation?.Invoke(currentHorizontalRotationVelocity);
 67
 068                yield return null;
 69            }
 070        }
 71    }
 72}