< 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:0
Uncovered lines:22
Coverable lines:22
Total lines:68
Line coverage:0% (0 of 22)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
FadeIn(...)0%2100%
FadeOut(...)0%2100%
FadeInCoroutine()0%20400%
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 DCL.Shaders;
 4using UnityEngine;
 5
 6namespace DCL.Controllers
 7{
 8    public interface IBlockerAnimationHandler
 9    {
 10        void FadeIn(GameObject go);
 11        void FadeOut(GameObject go, System.Action OnFinish);
 12    }
 13
 14    /// <summary>
 15    /// This class is in charge of handling the FadeIn/FadeOut animation
 16    /// of blockers.
 17    /// </summary>
 18    public class BlockerAnimationHandler : IBlockerAnimationHandler
 19    {
 20        public void FadeIn(GameObject go)
 21        {
 022            CoroutineStarter.Start(FadeInCoroutine(go));
 023        }
 24
 25        public void FadeOut(GameObject go, System.Action OnFinish)
 26        {
 027            CoroutineStarter.Start(FadeOutCoroutine(go, OnFinish));
 028        }
 29
 30        IEnumerator FadeInCoroutine(GameObject go)
 31        {
 032            Renderer rend = go.GetComponent<Renderer>();
 33
 034            Color color = rend.material.GetColor(ShaderUtils.BaseColor);
 35
 036            while (color.a < 0.5f)
 37            {
 038                color.a += Time.deltaTime;
 039                rend.material.SetColor(ShaderUtils.BaseColor, color);
 040                yield return null;
 41            }
 042        }
 43
 44        IEnumerator FadeOutCoroutine(GameObject go, System.Action OnFinish)
 45        {
 46#if UNITY_STANDALONE || UNITY_EDITOR
 047            if (DataStore.i.common.isApplicationQuitting.Get())
 048                yield break;
 49#endif
 50
 051            Renderer rend = go.GetComponent<Renderer>();
 52
 053            Color color = rend.material.GetColor(ShaderUtils.BaseColor);
 54
 055            while (color.a > 0)
 56            {
 057                if (rend == null)
 58                    break;
 59
 060                color.a -= Time.deltaTime;
 061                rend.material.SetColor(ShaderUtils.BaseColor, color);
 062                yield return null;
 63            }
 64
 065            OnFinish?.Invoke();
 066        }
 67    }
 68}