< Summary

Class:PreviewCameraRotation
Assembly:AvatarEditorHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/AvatarEditorHUD/Scripts/PreviewCameraRotation.cs
Covered lines:2
Uncovered lines:20
Coverable lines:22
Total lines:62
Line coverage:9% (2 of 22)
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%6200%
SlowDown()0%30500%

File(s)

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

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using UnityEngine;
 4using UnityEngine.EventSystems;
 5
 6public class PreviewCameraRotation : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
 7{
 8    public event System.Action<float> OnHorizontalRotation;
 9
 4710    public float rotationFactor = -15f;
 11
 4712    public float slowDownTime = 0.5f;
 13
 14    private float currentHorizontalRotationVelocity = 0f;
 15
 16    private float slowDownVelocity;
 17
 18    private Coroutine slowDownCoroutine;
 19
 20    private float timer;
 21
 022    public void OnBeginDrag(PointerEventData eventData) { AudioScriptableObjects.buttonClick.Play(true); }
 23
 24    public void OnDrag(PointerEventData eventData)
 25    {
 026        if (slowDownCoroutine != null)
 27        {
 028            StopCoroutine(slowDownCoroutine);
 029            slowDownCoroutine = null;
 30        }
 31
 032        currentHorizontalRotationVelocity = rotationFactor * eventData.delta.x;
 033        OnHorizontalRotation?.Invoke(currentHorizontalRotationVelocity);
 034    }
 35
 36    public void OnEndDrag(PointerEventData eventData)
 37    {
 038        timer = slowDownTime;
 039        slowDownVelocity = currentHorizontalRotationVelocity;
 40
 041        if (slowDownCoroutine == null)
 42        {
 043            slowDownCoroutine = StartCoroutine(SlowDown());
 44        }
 45
 046        AudioScriptableObjects.buttonRelease.Play(true);
 047    }
 48
 49    private IEnumerator SlowDown()
 50    {
 051        float inverseTimer = 1f / slowDownTime;
 52
 053        while (timer > 0)
 54        {
 055            timer -= Time.deltaTime;
 056            currentHorizontalRotationVelocity  = Mathf.Lerp(slowDownVelocity, 0, 1 - (timer * inverseTimer));
 057            OnHorizontalRotation?.Invoke(currentHorizontalRotationVelocity);
 58
 059            yield return null;
 60        }
 061    }
 62}