< 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")]
 311    public float defaultDuration = 1.0f;
 12
 913    public Coroutine CurrentRoutine { private set; get; } = null;
 14
 315    private CanvasGroup canvasGroup = null;
 316    private float alpha = 0.0f;
 17
 318    private float quickFadeDuration = 0.25f;
 19
 20    private void Awake()
 221    {
 222        canvasGroup = GetComponent<CanvasGroup>();
 223    }
 24
 25    public void StartFadeIn()
 126    {
 127        StopAllCoroutines();
 128        CurrentRoutine = StartCoroutine(FadeIn(defaultDuration));
 129    }
 30
 31    public void StartFadeOut()
 332    {
 333        StopAllCoroutines();
 334        CurrentRoutine = StartCoroutine(FadeOut(defaultDuration));
 335    }
 36
 37    public void QuickFadeIn()
 138    {
 139        StopAllCoroutines();
 140        CurrentRoutine = StartCoroutine(FadeIn(quickFadeDuration));
 141    }
 42
 43    public void QuickFadeOut()
 144    {
 145        StopAllCoroutines();
 146        CurrentRoutine = StartCoroutine(FadeOut(quickFadeDuration));
 147    }
 48
 49    private IEnumerator FadeIn(float duration)
 250    {
 251        float elapsedTime = 0.0f;
 52
 1153        while (alpha <= 1.0f)
 1054        {
 1055            SetAlpha(elapsedTime / duration);
 1056            elapsedTime += Time.deltaTime;
 1057            yield return null;
 958        }
 159    }
 60
 61    private IEnumerator FadeOut(float duration)
 462    {
 463        float elapsedTime = 0.0f;
 64
 3065        while (alpha >= 0.0f)
 2666        {
 2667            SetAlpha(1 - (elapsedTime / duration));
 2668            elapsedTime += Time.deltaTime;
 2669            yield return null;
 2670        }
 471    }
 72
 73    private void SetAlpha(float value)
 3674    {
 3675        alpha = value;
 3676        canvasGroup.alpha = alpha;
 3677    }
 78}