< Summary

Class:UIHelper_ClickBlocker
Assembly:UIComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Utils/UIHelper_ClickBlocker.cs
Covered lines:18
Uncovered lines:0
Coverable lines:18
Total lines:69
Line coverage:100% (18 of 18)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
OnDestroy()0%110100%
Activate()0%330100%
Deactivate()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Utils/UIHelper_ClickBlocker.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using UnityEngine;
 4using UnityEngine.UI;
 5
 6/// <summary>
 7/// Creates a fullscreen blocker above all UIs.
 8/// It will ignore the specific UIs set in the 'nonBlockingCanvas' list.
 9/// </summary>
 10public class UIHelper_ClickBlocker : MonoBehaviour
 11{
 12    [Header("Prefab References")]
 13    [SerializeField] internal Canvas blockerCanvas;
 14    [SerializeField] internal RectTransform blockerTransform;
 15    [SerializeField] internal Button blockerButton;
 16
 17    [Header("Optional Settings")]
 18    [SerializeField] internal List<Canvas> nonBlockingCanvas;
 19
 20    /// <summary>
 21    /// Event that will be triggered when the blocker is clicked.
 22    /// </summary>
 23    public event Action OnClicked;
 24
 25    internal Canvas parentcanvas = null;
 26
 27    private void Awake()
 28    {
 429        blockerButton.onClick.AddListener(() => OnClicked?.Invoke());
 430    }
 31
 32    private void OnDestroy()
 33    {
 434        blockerButton.onClick.RemoveAllListeners();
 435    }
 36
 37    /// <summary>
 38    /// Activates the blocker.
 39    /// </summary>
 40    public void Activate()
 41    {
 442        if (parentcanvas == null)
 443            parentcanvas = GetComponentInParent<Canvas>();
 44
 445        blockerTransform.SetParent(parentcanvas.rootCanvas.transform);
 46
 447        blockerTransform.offsetMax = Vector2.zero;
 448        blockerTransform.offsetMin = Vector2.zero;
 449        gameObject.SetActive(true);
 2450        foreach (Canvas canvas in nonBlockingCanvas)
 51        {
 852            canvas.overrideSorting = true;
 853            canvas.sortingOrder = blockerCanvas.sortingOrder + 1;
 54        }
 455    }
 56
 57
 58    /// <summary>
 59    /// Deactivates the blocker.
 60    /// </summary>
 61    public void Deactivate()
 62    {
 13263        gameObject.SetActive(false);
 79264        foreach (Canvas canvas in nonBlockingCanvas)
 65        {
 26466            canvas.overrideSorting = false;
 67        }
 13268    }
 69}