< Summary

Class:UIRadialRainbow
Assembly:RenderingUIScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/UI/Rainbow/UIRadialRainbow.cs
Covered lines:2
Uncovered lines:33
Coverable lines:35
Total lines:90
Line coverage:5.7% (2 of 35)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UIRadialRainbow()0%110100%
Start()0%6200%
FixedUpdate()0%6200%
SetValues()0%30500%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/UI/Rainbow/UIRadialRainbow.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using UnityEngine;
 4using UnityEngine.UI;
 5
 6public class UIRadialRainbow : MonoBehaviour
 7{
 8    Material targetMat;
 9    public Image img;
 10    public Texture mask;
 4011    public Color innerColor = Color.white;
 4012    public Vector2 frameThickness = new Vector2(1f,1f);
 13    public bool useTexture;
 14    public Texture gradientTexture;
 15    public Gradient gradient;
 16    public Vector2 speed;
 17    [Range(-360, 360)]
 18    public float rotation;
 19
 20    void Start()
 21    {
 022        if(img.maskable)
 23        {
 024            targetMat = img.materialForRendering;
 25        }
 26        else
 27        {
 028            targetMat = new Material(img.material);
 029            img.material = targetMat;
 30        }
 031    }
 32
 33
 34    void FixedUpdate()
 35    {
 036        if(targetMat)
 37        {
 038            SetValues();
 39        }
 40
 041    }
 42
 43    void SetValues()
 44    {
 045        targetMat.SetTexture("_Mask", mask);
 046        targetMat.SetColor("_InnerColor", innerColor);
 047        targetMat.SetVector("_FrameThickness", frameThickness);
 048        targetMat.SetTexture("_Ramp", gradientTexture);
 049        targetMat.SetVector("_Speed", speed);
 050        targetMat.SetFloat("_Rotation", rotation);
 51
 052        if (useTexture)
 53        {
 054            targetMat.SetFloat("_UseTexture", 1);
 55        }
 56        else
 57        {
 058            targetMat.SetFloat("_UseTexture", 0);
 59        }
 60
 061        targetMat.SetFloat("_ColorAmount", gradient.colorKeys.Length);
 62
 063        float[] tempPos01 = new float[4];
 064        float[] tempPos02 = new float[4];
 65
 066        for (int i = 0; i < 4; i++)
 67        {
 068            tempPos01[i] = 1;
 069            tempPos02[i] = 1;
 70        }
 71
 072        for (int i = 0; i < gradient.colorKeys.Length; i++)
 73        {
 074            targetMat.SetColor("_Color0" + (i + 1).ToString(), gradient.colorKeys[i].color);
 075            if (i <= 3)
 76            {
 077                tempPos01[i] = gradient.colorKeys[i].time;
 78            }
 79            else
 80            {
 081                tempPos02[i - 4] = gradient.colorKeys[i].time;
 82            }
 83        }
 084        Vector4 pos01 = new Vector4(tempPos01[0], tempPos01[1], tempPos01[2], tempPos01[3]);
 085        Vector4 pos02 = new Vector4(tempPos02[0], tempPos02[1], tempPos02[2], tempPos02[3]);
 86
 087        targetMat.SetVector("_GradientPositions01", pos01);
 088        targetMat.SetVector("_GradientPositions02", pos02);
 089    }
 90}