< 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    {
 1124        textReference.text = text;
 25
 1126        this.isEnableFunc = isEnableFunc;
 1127        this.onToggleAction = onToggleAction;
 28
 1129        bool isEnable = isEnableFunc?.Invoke() ?? false;
 1130        SetToggle(isEnable);
 1131    }
 32
 33    public void Dispose()
 34    {
 1035        if (!isDestroyed)
 36        {
 1037            Destroy(gameObject);
 38        }
 1039    }
 40
 41    private void Awake()
 42    {
 1143        buttonReference.onClick.AddListener(() =>
 44        {
 345            bool isEnable = isEnableFunc?.Invoke() ?? false;
 346            if (onToggleAction != null)
 47            {
 348                onToggleAction.Invoke(!isEnable);
 349                SetToggle(!isEnable);
 50            }
 351        });
 1152    }
 53
 54    private void OnDestroy()
 55    {
 1156        isDestroyed = true;
 1157    }
 58
 59    private void OnEnable()
 60    {
 1161        bool isEnable = isEnableFunc?.Invoke() ?? false;
 1162        SetToggle(isEnable);
 1163    }
 64
 65    private void SetToggle(bool isOn)
 66    {
 2567        Color color = isOn ? colorON : colorOFF;
 2568        imageReference.sprite = isOn ? imageON : imageOFF;
 2569        imageReference.color = color;
 2570        textReference.color = color;
 2571    }
 72}