< Summary

Class:DCL.Builder.ButtonColorChange
Assembly:BIWCommonHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/CommonHUD/Scripts/ButtonColorChange.cs
Covered lines:0
Uncovered lines:27
Coverable lines:27
Total lines:88
Line coverage:0% (0 of 27)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetColor(...)0%20400%
SetState(...)0%2100%
OnPointerDown(...)0%2100%
OnPointerUp(...)0%6200%
OnPointerEnter(...)0%2100%
OnPointerExit(...)0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/CommonHUD/Scripts/ButtonColorChange.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using UnityEngine;
 5using UnityEngine.EventSystems;
 6using UnityEngine.UI;
 7
 8namespace DCL.Builder
 9{
 10    public class ButtonColorChange : MonoBehaviour,
 11                                     IPointerDownHandler, IPointerUpHandler,
 12                                     IPointerEnterHandler, IPointerExitHandler
 13    {
 14        [SerializeField] internal Image buttonImage;
 15        [SerializeField] internal Color onIdleColor;
 16        [SerializeField] internal Color onHoverColor;
 17        [SerializeField] internal Color onPressedColor;
 18        [SerializeField] internal Color onDisabledColor;
 19
 20        private bool isHovered;
 21        private bool isPressed;
 22
 23        public enum State
 24        {
 25            IDLE = 0,
 26            HOVER = 1,
 27            PRESSED = 2,
 28            DISABLED = 3
 29        }
 30
 31        private State state = State.IDLE;
 32
 33        private void SetColor(State currentState)
 34        {
 035            Color colorToUse = onIdleColor;
 36            switch (currentState)
 37            {
 38                case State.HOVER:
 039                    colorToUse = onHoverColor;
 040                    break;
 41                case State.PRESSED:
 042                    colorToUse = onPressedColor;
 043                    break;
 44                case State.DISABLED:
 045                    colorToUse = onDisabledColor;
 46                    break;
 47
 48            }
 049            buttonImage.color = colorToUse;
 050        }
 51
 52        private void SetState(State state)
 53        {
 054            this.state = state;
 055            SetColor(state);
 056        }
 57
 58        public void OnPointerDown(PointerEventData eventData)
 59        {
 060            isPressed = true;
 061            SetState(State.PRESSED);
 062        }
 63
 64        public void OnPointerUp(PointerEventData eventData)
 65        {
 066            isPressed = false;
 067            if(!isHovered)
 068                SetState(State.IDLE);
 69            else
 070                SetState(State.HOVER);
 071        }
 72
 73        public void OnPointerEnter(PointerEventData eventData)
 74        {
 075            isHovered = true;
 076            SetState(State.HOVER);
 077        }
 78
 79        public void OnPointerExit(PointerEventData eventData)
 80        {
 081            isHovered = false;
 082            if(!isPressed)
 083                SetState(State.IDLE);
 84            else
 085                SetState(State.PRESSED);
 086        }
 87    }
 88}