< 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
 1313    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()
 126    {
 127        StopAllCoroutines();
 128        CurrentRoutine = StartCoroutine(FadeIn(defaultDuration));
 129    }
 30
 31    public void StartFadeOut()
 432    {
 433        StopAllCoroutines();
 434        CurrentRoutine = StartCoroutine(FadeOut(defaultDuration));
 435    }
 36
 37    public void QuickFadeIn()
 138    {
 139        StopAllCoroutines();
 140        CurrentRoutine = StartCoroutine(FadeIn(quickFadeDuration));
 141    }
 42
 43    public void QuickFadeOut()
 244    {
 245        StopAllCoroutines();
 246        CurrentRoutine = StartCoroutine(FadeOut(quickFadeDuration));
 247    }
 48
 49    private IEnumerator FadeIn(float duration)
 250    {
 251        float elapsedTime = 0.0f;
 52
 653        while (alpha <= 1.0f)
 554        {
 555            SetAlpha(elapsedTime / duration);
 556            elapsedTime += Time.deltaTime;
 557            yield return null;
 458        }
 159    }
 60
 61    private IEnumerator FadeOut(float duration)
 662    {
 663        float elapsedTime = 0.0f;
 64
 2565        while (alpha >= 0.0f)
 2066        {
 2067            SetAlpha(1 - (elapsedTime / duration));
 2068            elapsedTime += Time.deltaTime;
 2069            yield return null;
 1970        }
 571    }
 72
 73    private void SetAlpha(float value)
 2574    {
 2575        alpha = value;
 2576        canvasGroup.alpha = alpha;
 2577    }
 78}