< Summary

Class:ToggleSpriteSwap
Assembly:UIHelpers
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/UIHelpers/ToggleSpriteSwap.cs
Covered lines:0
Uncovered lines:7
Coverable lines:7
Total lines:25
Line coverage:0% (0 of 7)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%2100%
Start()0%2100%
OnEnable()0%2100%
OnDisable()0%2100%
SetSprite(...)0%20400%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/UIHelpers/ToggleSpriteSwap.cs

#LineLine coverage
 1using UnityEngine;
 2using UnityEngine.UI;
 3
 4[RequireComponent(typeof(Toggle))]
 5public class ToggleSpriteSwap : MonoBehaviour
 6{
 7    public Image targetImage;
 8    public Sprite spriteOn;
 9    public Sprite spriteOff;
 10    private Toggle targetToggle;
 11
 012    private void Awake() { targetToggle = GetComponent<Toggle>(); }
 13
 014    protected void Start() { SetSprite(targetToggle.isOn); }
 15
 016    private void OnEnable() { targetToggle.onValueChanged.AddListener(SetSprite); }
 17
 018    private void OnDisable() { targetToggle.onValueChanged.RemoveListener(SetSprite); }
 19
 20    private void SetSprite(bool newEnabled)
 21    {
 022        if (targetImage != null)
 023            targetImage.sprite = newEnabled ? spriteOn : spriteOff;
 024    }
 25}