< Summary

Class:FadeCanvas
Assembly:Test
File(s):E:/Unity/Unity Project/VR-Basics/Assets/_Course Library/Scripts/Core/FadeCanvas.cs
Covered lines:25
Uncovered lines:21
Coverable lines:46
Total lines:78
Line coverage:54.3% (25 of 46)
Covered branches:0
Total branches:0
Covered methods:7
Total methods:11
Method coverage:63.6% (7 of 11)

Coverage History

Metrics

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

File(s)

E:/Unity/Unity Project/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")]
 411    public float defaultDuration = 1.0f;
 12
 613    public Coroutine CurrentRoutine { private set; get; } = null;
 14
 415    private CanvasGroup canvasGroup = null;
 416    private float alpha = 0.0f;
 17
 418    private float quickFadeDuration = 0.25f;
 19
 20    private void Awake()
 221    {
 222        canvasGroup = GetComponent<CanvasGroup>();
 223    }
 24
 25    public void StartFadeIn()
 026    {
 027        StopAllCoroutines();
 028        CurrentRoutine = StartCoroutine(FadeIn(defaultDuration));
 029    }
 30
 31    public void StartFadeOut()
 232    {
 233        StopAllCoroutines();
 234        CurrentRoutine = StartCoroutine(FadeOut(defaultDuration));
 235    }
 36
 37    public void QuickFadeIn()
 038    {
 039        StopAllCoroutines();
 040        CurrentRoutine = StartCoroutine(FadeIn(quickFadeDuration));
 041    }
 42
 43    public void QuickFadeOut()
 044    {
 045        StopAllCoroutines();
 046        CurrentRoutine = StartCoroutine(FadeOut(quickFadeDuration));
 047    }
 48
 49    private IEnumerator FadeIn(float duration)
 050    {
 051        float elapsedTime = 0.0f;
 52
 053        while (alpha <= 1.0f)
 054        {
 055            SetAlpha(elapsedTime / duration);
 056            elapsedTime += Time.deltaTime;
 057            yield return null;
 058        }
 059    }
 60
 61    private IEnumerator FadeOut(float duration)
 262    {
 263        float elapsedTime = 0.0f;
 64
 1265        while (alpha >= 0.0f)
 1066        {
 1067            SetAlpha(1 - (elapsedTime / duration));
 1068            elapsedTime += Time.deltaTime;
 1069            yield return null;
 1070        }
 271    }
 72
 73    private void SetAlpha(float value)
 1074    {
 1075        alpha = value;
 1076        canvasGroup.alpha = alpha;
 1077    }
 78}