< Summary

Class:FadeCanvas
Assembly:Test
File(s):D:/--UnityProject/VR/_____ISSTA 26/VR-Basics/Assets/_Course Library/Scripts/Core/FadeCanvas.cs
Covered lines:46
Uncovered lines:0
Coverable lines:46
Total lines:78
Line coverage:100% (46 of 46)
Covered branches:0
Total branches:0
Covered methods:11
Total methods:11
Method coverage:100% (11 of 11)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
FadeCanvas()0%000100%
Awake()0%000100%
StartFadeIn()0%000100%
StartFadeOut()0%000100%
QuickFadeIn()0%000100%
QuickFadeOut()0%000100%
FadeIn()0%000100%
FadeOut()0%000100%
SetAlpha(...)0%000100%

File(s)

D:/--UnityProject/VR/_____ISSTA 26/VR-Basics/Assets/_Course Library/Scripts/Core/FadeCanvas.cs

#LineLine coverage
 1using System.Collections;
 2using UnityEngine;
 3
 4/// <summary>
 5/// Fades a canvas over time using a coroutine and a canvas group
 6/// </summary>
 7[RequireComponent(typeof(CanvasGroup))]
 8public class FadeCanvas : MonoBehaviour
 9{
 10    [Tooltip("The speed at which the canvas fades")]
 511    public float defaultDuration = 1.0f;
 12
 1913    public Coroutine CurrentRoutine { private set; get; } = null;
 14
 515    private CanvasGroup canvasGroup = null;
 516    private float alpha = 0.0f;
 17
 518    private float quickFadeDuration = 0.25f;
 19
 20    private void Awake()
 321    {
 322        canvasGroup = GetComponent<CanvasGroup>();
 323    }
 24
 25    public void StartFadeIn()
 226    {
 227        StopAllCoroutines();
 228        CurrentRoutine = StartCoroutine(FadeIn(defaultDuration));
 229    }
 30
 31    public void StartFadeOut()
 632    {
 633        StopAllCoroutines();
 634        CurrentRoutine = StartCoroutine(FadeOut(defaultDuration));
 635    }
 36
 37    public void QuickFadeIn()
 238    {
 239        StopAllCoroutines();
 240        CurrentRoutine = StartCoroutine(FadeIn(quickFadeDuration));
 241    }
 42
 43    public void QuickFadeOut()
 444    {
 445        StopAllCoroutines();
 446        CurrentRoutine = StartCoroutine(FadeOut(quickFadeDuration));
 447    }
 48
 49    private IEnumerator FadeIn(float duration)
 450    {
 451        float elapsedTime = 0.0f;
 52
 1953        while (alpha <= 1.0f)
 1754        {
 1755            SetAlpha(elapsedTime / duration);
 1756            elapsedTime += Time.deltaTime;
 1757            yield return null;
 1558        }
 259    }
 60
 61    private IEnumerator FadeOut(float duration)
 1062    {
 1063        float elapsedTime = 0.0f;
 64
 3465        while (alpha >= 0.0f)
 2666        {
 2667            SetAlpha(1 - (elapsedTime / duration));
 2668            elapsedTime += Time.deltaTime;
 2669            yield return null;
 2470        }
 871    }
 72
 73    private void SetAlpha(float value)
 4374    {
 4375        alpha = value;
 4376        canvasGroup.alpha = alpha;
 4377    }
 78}