< Summary

Class:CursorController
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/CursorController.cs
Covered lines:29
Uncovered lines:3
Coverable lines:32
Total lines:75
Line coverage:90.6% (29 of 32)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
Show()0%5.685070%
Hide()0%5.155081.82%
SetNormalCursor()0%110100%
SetHoverCursor()0%110100%
SetAlpha()0%550100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/CursorController.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using UnityEngine;
 4using UnityEngine.UI;
 5
 6public class CursorController : MonoBehaviour
 7{
 8    private const float ALPHA_INTERPOLATION_DURATION = 0.1f;
 9
 010    public static CursorController i { get; private set; }
 11    public Image cursorImage;
 12    public Sprite normalCursor;
 13    public Sprite hoverCursor;
 14    public CanvasGroup canvasGroup;
 15
 16    private Coroutine alphaRoutine;
 17
 120418    void Awake() { i = this; }
 19
 20    public void Show()
 21    {
 7922        if (cursorImage == null) return;
 2323        if (cursorImage.gameObject.activeSelf) return;
 24
 325        cursorImage.gameObject.SetActive(true);
 26
 327        if (gameObject.activeSelf)
 28        {
 029            if (alphaRoutine != null) StopCoroutine(alphaRoutine);
 030            alphaRoutine = StartCoroutine(SetAlpha(0f, 1f, ALPHA_INTERPOLATION_DURATION));
 31        }
 332    }
 33
 34    public void Hide()
 35    {
 83036        if (cursorImage == null) return;
 57437        if (!cursorImage.gameObject.activeSelf) return;
 38
 57439        if (gameObject.activeSelf)
 40        {
 56941            if (alphaRoutine != null) StopCoroutine(alphaRoutine);
 56942            alphaRoutine = StartCoroutine(SetAlpha(1f, 0f, ALPHA_INTERPOLATION_DURATION,
 13943                () => cursorImage.gameObject.SetActive(false)));
 56944        }
 45        else
 546            cursorImage.gameObject.SetActive(false);
 547    }
 48
 49    public void SetNormalCursor()
 50    {
 1051        cursorImage.sprite = normalCursor;
 1052        cursorImage.SetNativeSize();
 1053    }
 54
 55    public void SetHoverCursor()
 56    {
 557        cursorImage.sprite = hoverCursor;
 558        cursorImage.SetNativeSize();
 559    }
 60
 61    private IEnumerator SetAlpha(float from, float to, float duration, Action callback = null)
 62    {
 56963        var time = 0f;
 64
 286165        while (time < duration)
 66        {
 272267            time += Time.deltaTime;
 272268            canvasGroup.alpha = Mathf.Lerp(from, to, time / duration);
 272269            yield return null;
 70        }
 71
 13972        canvasGroup.alpha = to;
 13973        callback?.Invoke();
 13974    }
 75}