< 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")]
 211    public float defaultDuration = 1.0f;
 12
 313    public Coroutine CurrentRoutine { private set; get; } = null;
 14
 215    private CanvasGroup canvasGroup = null;
 216    private float alpha = 0.0f;
 17
 218    private float quickFadeDuration = 0.25f;
 19
 20    private void Awake()
 121    {
 122        canvasGroup = GetComponent<CanvasGroup>();
 123    }
 24
 25    public void StartFadeIn()
 026    {
 027        StopAllCoroutines();
 028        CurrentRoutine = StartCoroutine(FadeIn(defaultDuration));
 029    }
 30
 31    public void StartFadeOut()
 132    {
 133        StopAllCoroutines();
 134        CurrentRoutine = StartCoroutine(FadeOut(defaultDuration));
 135    }
 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)
 162    {
 163        float elapsedTime = 0.0f;
 64
 665        while (alpha >= 0.0f)
 566        {
 567            SetAlpha(1 - (elapsedTime / duration));
 568            elapsedTime += Time.deltaTime;
 569            yield return null;
 570        }
 171    }
 72
 73    private void SetAlpha(float value)
 574    {
 575        alpha = value;
 576        canvasGroup.alpha = alpha;
 577    }
 78}