< 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
 808810    public bool hideOnEnable = true;
 808811    public float animSpeedFactor = 1.0f;
 12    public bool disableAfterFadeOut;
 808813    public string visibleParam = "visible";
 14
 5415    public bool isVisible => animator.GetBool(visibleParamHash);
 16
 17    private Animator animatorValue;
 18
 19    private Animator animator
 20    {
 21        get
 22        {
 322023            if (animatorValue == null)
 24            {
 59025                animatorValue = GetComponent<Animator>();
 26            }
 27
 322028            return animatorValue;
 29        }
 30    }
 31
 32    private int? visibleParamHashValue = null;
 33
 34    private int visibleParamHash
 35    {
 36        get
 37        {
 81738            if (!visibleParamHashValue.HasValue)
 58539                visibleParamHashValue = Animator.StringToHash(visibleParam);
 40
 81741            return visibleParamHashValue.Value;
 42        }
 43    }
 44
 45    public void Show(bool instant = false)
 46    {
 13347        animator.speed = animSpeedFactor;
 48
 13349        if ( animator.isActiveAndEnabled )
 12250            animator.SetBool(visibleParamHash, true);
 51
 13352        if (instant)
 953            animator.Update(10);
 13354    }
 55
 56    public void Hide(bool instant = false)
 57    {
 74258        animator.speed = animSpeedFactor;
 59
 74260        if ( animator.isActiveAndEnabled )
 64161            animator.SetBool(visibleParamHash, false);
 62
 74263        if (instant)
 64464            animator.Update(10);
 74265    }
 66
 67    public void AnimEvent_HideFinished()
 68    {
 3269        OnWillFinishHide?.Invoke(this);
 70
 3271        if (disableAfterFadeOut)
 72        {
 173            gameObject?.SetActive(false);
 74        }
 3275    }
 76
 2677    public void AnimEvent_ShowFinished() { OnWillFinishStart?.Invoke(this); }
 78
 79    private void OnEnable()
 80    {
 383981        if ( hideOnEnable )
 82        {
 53483            Hide(true);
 84        }
 383985    }
 86}