< Summary

Class:PreviewMenuVisibilityToggleView
Assembly:DebugPlugins_PreviewMenu
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/DebugPlugins/PreviewMenu/View/Scripts/PreviewMenuVisibilityToggleView.cs
Covered lines:26
Uncovered lines:0
Coverable lines:26
Total lines:72
Line coverage:100% (26 of 26)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp(...)0%330100%
Dispose()0%220100%
Awake()0%110100%
OnDestroy()0%110100%
OnEnable()0%330100%
SetToggle(...)0%550100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/DebugPlugins/PreviewMenu/View/Scripts/PreviewMenuVisibilityToggleView.cs

#LineLine coverage
 1using System;
 2using TMPro;
 3using UnityEngine;
 4using UnityEngine.UI;
 5
 6internal class PreviewMenuVisibilityToggleView : MonoBehaviour, IDisposable
 7{
 8    [SerializeField] internal Color colorON;
 9    [SerializeField] internal Color colorOFF;
 10    [SerializeField] internal Sprite imageON;
 11    [SerializeField] internal Sprite imageOFF;
 12
 13    [SerializeField] internal TextMeshProUGUI textReference;
 14    [SerializeField] internal Image imageReference;
 15    [SerializeField] internal Button buttonReference;
 16
 17    private Func<bool> isEnableFunc;
 18    private Action<bool> onToggleAction;
 19
 20    private bool isDestroyed;
 21
 22    public void SetUp(string text, Func<bool> isEnableFunc, Action<bool> onToggleAction)
 23    {
 1624        textReference.text = text;
 25
 1626        this.isEnableFunc = isEnableFunc;
 1627        this.onToggleAction = onToggleAction;
 28
 1629        bool isEnable = isEnableFunc?.Invoke() ?? false;
 1630        SetToggle(isEnable);
 1631    }
 32
 33    public void Dispose()
 34    {
 1535        if (!isDestroyed)
 36        {
 1537            Destroy(gameObject);
 38        }
 1539    }
 40
 41    private void Awake()
 42    {
 1643        buttonReference.onClick.AddListener(() =>
 44        {
 345            bool isEnable = isEnableFunc?.Invoke() ?? false;
 346            if (onToggleAction != null)
 47            {
 348                onToggleAction.Invoke(!isEnable);
 349                SetToggle(!isEnable);
 50            }
 351        });
 1652    }
 53
 54    private void OnDestroy()
 55    {
 1656        isDestroyed = true;
 1657    }
 58
 59    private void OnEnable()
 60    {
 1661        bool isEnable = isEnableFunc?.Invoke() ?? false;
 1662        SetToggle(isEnable);
 1663    }
 64
 65    private void SetToggle(bool isOn)
 66    {
 3567        Color color = isOn ? colorON : colorOFF;
 3568        imageReference.sprite = isOn ? imageON : imageOFF;
 3569        imageReference.color = color;
 3570        textReference.color = color;
 3571    }
 72}