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

Metrics

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

File(s)

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

#LineLine coverage
 1using System;
 2using UnityEngine;
 3
 4[RequireComponent(typeof(Animator))]
 5public class ShowHideAnimator : MonoBehaviour
 6{
 7    public event System.Action<ShowHideAnimator> OnWillFinishHide;
 8    public event System.Action<ShowHideAnimator> OnWillFinishStart;
 9
 773410    public bool hideOnEnable = true;
 773411    public float animSpeedFactor = 1.0f;
 12    public bool disableAfterFadeOut;
 773413    public string visibleParam = "visible";
 14
 4815    public bool isVisible => animator.GetBool(visibleParamHash);
 16
 17    private Animator animatorValue;
 18
 19    private Animator animator
 20    {
 21        get
 22        {
 231123            if (animatorValue == null)
 24            {
 44325                animatorValue = GetComponent<Animator>();
 26            }
 27
 231128            return animatorValue;
 29        }
 30    }
 31
 32    private int? visibleParamHashValue = null;
 33
 34    private int visibleParamHash
 35    {
 36        get
 37        {
 59038            if (!visibleParamHashValue.HasValue)
 43839                visibleParamHashValue = Animator.StringToHash(visibleParam);
 40
 59041            return visibleParamHashValue.Value;
 42        }
 43    }
 44
 45    public void Show(bool instant = false)
 46    {
 8547        animator.speed = animSpeedFactor;
 48
 8549        if ( animator.isActiveAndEnabled )
 7650            animator.SetBool(visibleParamHash, true);
 51
 8552        if (instant)
 753            animator.Update(10);
 8554    }
 55
 56    public void Hide(bool instant = false)
 57    {
 52958        animator.speed = animSpeedFactor;
 59
 52960        if ( animator.isActiveAndEnabled )
 46661            animator.SetBool(visibleParamHash, false);
 62
 52963        if (instant)
 48664            animator.Update(10);
 52965    }
 66
 67    public void AnimEvent_HideFinished()
 68    {
 2769        OnWillFinishHide?.Invoke(this);
 70
 2771        if (disableAfterFadeOut)
 72        {
 373            gameObject?.SetActive(false);
 74        }
 2775    }
 76
 1877    public void AnimEvent_ShowFinished() { OnWillFinishStart?.Invoke(this); }
 78
 79    private void OnEnable()
 80    {
 458281        if ( hideOnEnable )
 82        {
 41883            Hide(true);
 84        }
 458285    }
 86}