< Summary

Class:ShowHideAnimator
Assembly:HUDCommon
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Common/ShowHideAnimator/ShowHideAnimator.cs
Covered lines:26
Uncovered lines:0
Coverable lines:26
Total lines:73
Line coverage:100% (26 of 26)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ShowHideAnimator()0%110100%
Awake()0%330100%
OnEnable()0%220100%
Show(...)0%220100%
Hide(...)0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Common/ShowHideAnimator/ShowHideAnimator.cs

#LineLine coverage
 1using DG.Tweening;
 2using UnityEngine;
 3
 4public class ShowHideAnimator : MonoBehaviour
 5{
 6    private const float BASE_DURATION = 0.2f;
 7
 8    public event System.Action<ShowHideAnimator> OnWillFinishHide;
 9    public event System.Action<ShowHideAnimator> OnWillFinishStart;
 10
 1759111    public bool hideOnEnable = true;
 1759112    public float animSpeedFactor = 1.0f;
 13    public bool disableAfterFadeOut;
 14
 15    [SerializeField] private CanvasGroup canvasGroup;
 16
 17    private int? visibleParamHashValue = null;
 18
 5319    public bool isVisible => canvasGroup == null || canvasGroup.blocksRaycasts;
 20
 21    private void Awake()
 22    {
 1172523        if (TryGetComponent(out Animator animator)) //Remove old behaviour
 1156324            Destroy(animator);
 25
 1172526        if (canvasGroup == null)
 648627            canvasGroup = GetComponent<CanvasGroup>();
 1172528    }
 29
 30    private void OnEnable()
 31    {
 1760932        if (hideOnEnable)
 33        {
 61834            Hide(true);
 35        }
 1760936    }
 37
 38    public void Show(bool instant = false)
 39    {
 17240        canvasGroup.blocksRaycasts = true;
 41
 42        //When instant, we use duration 0 instead of just modifying the canvas group to mock the old animator behaviour 
 17243        var duration = instant ? 0 : BASE_DURATION * animSpeedFactor;
 17244        canvasGroup.DOKill();
 17245        canvasGroup.DOFade(1, duration)
 46                   .SetEase(Ease.InOutQuad)
 847                   .OnComplete(() => OnWillFinishStart?.Invoke(this))
 48                   .SetLink(canvasGroup.gameObject, LinkBehaviour.KillOnDestroy)
 49                   .SetLink(canvasGroup.gameObject, LinkBehaviour.KillOnDisable);
 17250    }
 51
 52    public void Hide(bool instant = false)
 53    {
 101054        canvasGroup.blocksRaycasts = false;
 55
 56        //When instant, we use duration 0 instead of just modifying the canvas group to mock the old animator behaviour 
 101057        var duration = instant ? 0 : BASE_DURATION * animSpeedFactor;
 101058        canvasGroup.DOKill();
 101059        canvasGroup.DOFade(0, duration)
 60                   .SetEase(Ease.InOutQuad)
 61                   .OnComplete(() =>
 62                   {
 9263                       OnWillFinishHide?.Invoke(this);
 64
 9265                       if (disableAfterFadeOut && gameObject != null)
 66                       {
 5967                           gameObject.SetActive(false);
 68                       }
 9269                   })
 70                   .SetLink(canvasGroup.gameObject, LinkBehaviour.KillOnDestroy)
 71                   .SetLink(canvasGroup.gameObject, LinkBehaviour.KillOnDisable);
 101072    }
 73}