< Summary

Class:DCL.Controllers.BlockerAnimationHandler
Assembly:WorldBlockersController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/BlockerController/BlockerAnimationHandler.cs
Covered lines:6
Uncovered lines:16
Coverable lines:22
Total lines:67
Line coverage:27.2% (6 of 22)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
FadeIn(...)0%110100%
FadeOut(...)0%2100%
FadeInCoroutine()0%5.264057.14%
FadeOutCoroutine()0%56700%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/BlockerController/BlockerAnimationHandler.cs

#LineLine coverage
 1using System.Collections;
 2using DCL.Helpers;
 3using UnityEngine;
 4
 5namespace DCL.Controllers
 6{
 7    public interface IBlockerAnimationHandler
 8    {
 9        void FadeIn(GameObject go);
 10        void FadeOut(GameObject go, System.Action OnFinish);
 11    }
 12
 13    /// <summary>
 14    /// This class is in charge of handling the FadeIn/FadeOut animation
 15    /// of blockers.
 16    /// </summary>
 17    public class BlockerAnimationHandler : IBlockerAnimationHandler
 18    {
 19        public void FadeIn(GameObject go)
 20        {
 3221            CoroutineStarter.Start(FadeInCoroutine(go));
 3222        }
 23
 24        public void FadeOut(GameObject go, System.Action OnFinish)
 25        {
 026            CoroutineStarter.Start(FadeOutCoroutine(go, OnFinish));
 027        }
 28
 29        IEnumerator FadeInCoroutine(GameObject go)
 30        {
 3231            Renderer rend = go.GetComponent<Renderer>();
 32
 3233            Color color = rend.material.GetColor(ShaderUtils.BaseColor);
 34
 3235            while (color.a < 0.5f)
 36            {
 037                color.a += Time.deltaTime;
 038                rend.material.SetColor(ShaderUtils.BaseColor, color);
 039                yield return null;
 40            }
 3241        }
 42
 43        IEnumerator FadeOutCoroutine(GameObject go, System.Action OnFinish)
 44        {
 45#if UNITY_STANDALONE || UNITY_EDITOR
 046            if (DataStore.i.common.isApplicationQuitting.Get())
 047                yield break;
 48#endif
 49
 050            Renderer rend = go.GetComponent<Renderer>();
 51
 052            Color color = rend.material.GetColor(ShaderUtils.BaseColor);
 53
 054            while (color.a > 0)
 55            {
 056                if (rend == null)
 57                    break;
 58
 059                color.a -= Time.deltaTime;
 060                rend.material.SetColor(ShaderUtils.BaseColor, color);
 061                yield return null;
 62            }
 63
 064            OnFinish?.Invoke();
 065        }
 66    }
 67}