< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetShowHideAnimator(...)0%2100%
Awake()0%220100%
OnPointerEnter(...)0%2100%
OnPointerExit(...)0%2100%
DelayRoutine()0%30500%
Show()0%2100%
Hide()0%2100%
StopDelayRoutine()0%6200%
StartDelayRoutine(...)0%2100%

File(s)

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

#LineLine coverage
 1using UnityEngine;
 2using UnityEngine.EventSystems;
 3using System;
 4using System.Collections;
 5
 6public class UIHoverTriggerShowHideAnimator : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
 7{
 8    [SerializeField] ShowHideAnimator showHideAnimator = null;
 9    [SerializeField] bool hideAnimatorOnAwake = false;
 10    [SerializeField] bool enableAnimatorOnHover = false;
 11
 12    [Range(0, 10)]
 13    [SerializeField] float setVisibleDelay = 0;
 14
 15    [Range(0, 10)]
 16    [SerializeField] float setHideDelay = 0;
 17
 18    Coroutine delayRoutine = null;
 19
 020    public void SetShowHideAnimator(ShowHideAnimator showHideAnimator) { this.showHideAnimator = showHideAnimator; }
 21
 22    void Awake()
 23    {
 21524        if (hideAnimatorOnAwake)
 25        {
 19826            showHideAnimator.gameObject.SetActive(false);
 27        }
 21528    }
 29
 030    void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData) { Show(); }
 31
 032    void IPointerExitHandler.OnPointerExit(PointerEventData eventData) { Hide(); }
 33
 34    IEnumerator DelayRoutine(float delay, Action callback)
 35    {
 036        if (delay > 0)
 37        {
 038            yield return new WaitForSeconds(delay);
 39        }
 040        callback?.Invoke();
 041    }
 42
 43    void Show()
 44    {
 045        StartDelayRoutine(setVisibleDelay, () =>
 46        {
 047            if (enableAnimatorOnHover && !showHideAnimator.gameObject.activeSelf)
 48            {
 049                showHideAnimator.gameObject.SetActive(true);
 50            }
 051            showHideAnimator.Show();
 052        });
 053    }
 54
 55    void Hide()
 56    {
 057        StartDelayRoutine(setHideDelay, () =>
 58        {
 059            showHideAnimator.Hide();
 060        });
 061    }
 62
 63    void StopDelayRoutine()
 64    {
 065        if (delayRoutine != null)
 66        {
 067            StopCoroutine(delayRoutine);
 68        }
 069    }
 70
 71    void StartDelayRoutine(float delay, Action callback)
 72    {
 073        StopDelayRoutine();
 074        delayRoutine = StartCoroutine(DelayRoutine(delay, callback));
 075    }
 76}