< Summary

Class:UIChargeWheel
Assembly:RenderingUIScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/UI/ChargeWheel/UIChargeWheel.cs
Covered lines:0
Uncovered lines:30
Coverable lines:30
Total lines:81
Line coverage:0% (0 of 30)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UIChargeWheel()0%2100%
Start()0%6200%
Update()0%12300%
ColorChange()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/UI/ChargeWheel/UIChargeWheel.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using UnityEngine;
 4using UnityEngine.UI;
 5
 6public class UIChargeWheel : MonoBehaviour
 7{
 8    Material _material;
 9    Image _img;
 010    public float speed = 1;
 11
 12    public Color[] colors;
 13    int colorIndex = 0;
 14
 15
 16    float head;
 17    float tail;
 18
 19    void Start()
 20    {
 021        _img = GetComponent<Image>();
 22
 023        if (_img.maskable)
 24        {
 025            _material = _img.materialForRendering;
 26        }
 27        else
 28        {
 029            _material = new Material(_img.material);
 030            _img.material = _material;
 31        }
 32
 033        _material.SetColor("_color01", colors[colorIndex]);
 34
 035        head = Random.Range(0, 0.15f);
 036    }
 37
 38
 39    void Update()
 40    {
 041        float tempSpeedH = Mathf.Abs(0.5f + head) * speed;
 042        float tempSpeedT = Mathf.Abs(0.5f + tail) * speed;
 43
 044        if (head < 1)
 45        {
 046            head += tempSpeedH * Time.deltaTime;
 047            head = Mathf.Clamp01(head);
 048            _material.SetFloat("_fillHead", head);
 49        }
 050        else if(tail < 1)
 51        {
 052            tail += tempSpeedT * Time.deltaTime;
 053            tail = Mathf.Clamp01(tail);
 054            _material.SetFloat("_fillTail", tail);
 55        }
 56        else
 57        {
 058            head = 0;
 059            tail = 0;
 60
 061            _material.SetFloat("_fillHead", head);
 062            _material.SetFloat("_fillTail", tail);
 63
 064            ColorChange();
 65        }
 066    }
 67
 68    void ColorChange()
 69    {
 070        if(colorIndex < colors.Length - 1)
 71        {
 072            colorIndex++;
 73        }
 74        else
 75        {
 076            colorIndex = 0;
 77        }
 78
 079        _material.SetColor("_color01", colors[colorIndex]);
 080    }
 81}