< Summary

Class:SaveHUDView
Assembly:BuildModeHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/BuildModeHUD/Scripts/Common/SaveHUDView.cs
Covered lines:13
Uncovered lines:32
Coverable lines:45
Total lines:103
Line coverage:28.8% (13 of 45)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SaveHUDView()0%110100%
OnDisable()0%110100%
SceneStateSaved()0%2100%
StopAnimation()0%2.262060%
SetFirstPersonView()0%110100%
SetGodModeView()0%2100%
SetViewByEntityListOpen(...)0%6200%
SceneStateSaveAnimation()0%56700%
HideSaveImage()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/BuildModeHUD/Scripts/Common/SaveHUDView.cs

#LineLine coverage
 1using System.Collections;
 2using UnityEngine;
 3using UnityEngine.UI;
 4
 5public interface ISaveHUDView
 6{
 7    void SetFirstPersonView();
 8    void SetGodModeView();
 9    void SceneStateSaved();
 10    void StopAnimation();
 11    void SetViewByEntityListOpen(bool isOpen);
 12}
 13
 14public class SaveHUDView : MonoBehaviour, ISaveHUDView
 15{
 16    [Header("Animation design")]
 2017    [SerializeField] internal float saveAnimationSpeed = 1.25f;
 2018    [SerializeField] internal float sFullVisibleTime = 0.5f;
 2019    [SerializeField] internal float percentMinVisible = 0.25f;
 2020    [SerializeField] internal int totalAnimationTimes = 5;
 21
 22    [Header("References")]
 23    [SerializeField] internal Image saveImg;
 24    [SerializeField] internal RectTransform godModePosition;
 25    [SerializeField] internal RectTransform godModeEntityListOpenPosition;
 26    [SerializeField] internal RectTransform firstPersonModePosition;
 27    [SerializeField] internal InspectorView inspectorView;
 28
 29    private Coroutine animationCourutine;
 30
 4031    private void OnDisable() { StopAnimation(); }
 32
 33    public void SceneStateSaved()
 34    {
 035        StopAnimation();
 036        animationCourutine =  CoroutineStarter.Start(SceneStateSaveAnimation());
 037    }
 38    public void StopAnimation()
 39    {
 2040        if (animationCourutine != null)
 41        {
 042            CoroutineStarter.Stop(animationCourutine);
 043            animationCourutine = null;
 44        }
 45
 2046        HideSaveImage();
 2047    }
 48
 249    public void SetFirstPersonView() { saveImg.rectTransform.anchoredPosition = firstPersonModePosition.anchoredPosition
 50
 051    public void SetGodModeView() { SetViewByEntityListOpen(inspectorView.IsActive()); }
 52
 053    public void SetViewByEntityListOpen(bool isOpen) { saveImg.rectTransform.anchoredPosition = isOpen ? godModeEntityLi
 54
 55    private IEnumerator SceneStateSaveAnimation()
 56    {
 057        float initialValue = percentMinVisible;
 058        float finalValue = 1;
 59
 060        Color from = saveImg.color;
 061        from.a = initialValue;
 062        Color to = saveImg.color;
 063        to.a = finalValue;
 64
 65        Color currentColor;
 66
 067        float currentAdvance = 0;
 068        int currentAnimationTimes = 0;
 069        while (currentAnimationTimes < totalAnimationTimes)
 70        {
 071            currentAdvance += saveAnimationSpeed * Time.deltaTime;
 072            currentColor = Color.Lerp(from, to, currentAdvance);
 073            saveImg.color = currentColor;
 74
 075            if (currentAdvance >= 1)
 76            {
 077                if (Mathf.Abs(from.a - initialValue) < 0.1f )
 78                {
 079                    from.a = finalValue;
 080                    to.a = initialValue;
 081                    yield return new WaitForSecondsRealtime(sFullVisibleTime);
 082                }
 83                else
 84                {
 085                    from.a = initialValue;
 086                    to.a = finalValue;
 87                }
 088                currentAnimationTimes++;
 089                currentAdvance = 0;
 90            }
 091            yield return null;
 92        }
 93
 094        HideSaveImage();
 095    }
 96
 97    private void HideSaveImage()
 98    {
 2099        Color final = saveImg.color;
 20100        final.a = 0;
 20101        saveImg.color = final;
 20102    }
 103}