| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | public class UIRadialRainbow : MonoBehaviour |
| | 7 | | { |
| | 8 | | Material targetMat; |
| | 9 | | public Image img; |
| | 10 | | public Texture mask; |
| 40 | 11 | | public Color innerColor = Color.white; |
| 40 | 12 | | 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 | | { |
| 0 | 22 | | if(img.maskable) |
| | 23 | | { |
| 0 | 24 | | targetMat = img.materialForRendering; |
| 0 | 25 | | } |
| | 26 | | else |
| | 27 | | { |
| 0 | 28 | | targetMat = new Material(img.material); |
| 0 | 29 | | img.material = targetMat; |
| | 30 | | } |
| 0 | 31 | | } |
| | 32 | |
|
| | 33 | |
|
| | 34 | | void FixedUpdate() |
| | 35 | | { |
| 0 | 36 | | if(targetMat) |
| | 37 | | { |
| 0 | 38 | | SetValues(); |
| | 39 | | } |
| | 40 | |
|
| 0 | 41 | | } |
| | 42 | |
|
| | 43 | | void SetValues() |
| | 44 | | { |
| 0 | 45 | | targetMat.SetTexture("_Mask", mask); |
| 0 | 46 | | targetMat.SetColor("_InnerColor", innerColor); |
| 0 | 47 | | targetMat.SetVector("_FrameThickness", frameThickness); |
| 0 | 48 | | targetMat.SetTexture("_Ramp", gradientTexture); |
| 0 | 49 | | targetMat.SetVector("_Speed", speed); |
| 0 | 50 | | targetMat.SetFloat("_Rotation", rotation); |
| | 51 | |
|
| 0 | 52 | | if (useTexture) |
| | 53 | | { |
| 0 | 54 | | targetMat.SetFloat("_UseTexture", 1); |
| 0 | 55 | | } |
| | 56 | | else |
| | 57 | | { |
| 0 | 58 | | targetMat.SetFloat("_UseTexture", 0); |
| | 59 | | } |
| | 60 | |
|
| 0 | 61 | | targetMat.SetFloat("_ColorAmount", gradient.colorKeys.Length); |
| | 62 | |
|
| 0 | 63 | | float[] tempPos01 = new float[4]; |
| 0 | 64 | | float[] tempPos02 = new float[4]; |
| | 65 | |
|
| 0 | 66 | | for (int i = 0; i < 4; i++) |
| | 67 | | { |
| 0 | 68 | | tempPos01[i] = 1; |
| 0 | 69 | | tempPos02[i] = 1; |
| | 70 | | } |
| | 71 | |
|
| 0 | 72 | | for (int i = 0; i < gradient.colorKeys.Length; i++) |
| | 73 | | { |
| 0 | 74 | | targetMat.SetColor("_Color0" + (i + 1).ToString(), gradient.colorKeys[i].color); |
| 0 | 75 | | if (i <= 3) |
| | 76 | | { |
| 0 | 77 | | tempPos01[i] = gradient.colorKeys[i].time; |
| 0 | 78 | | } |
| | 79 | | else |
| | 80 | | { |
| 0 | 81 | | tempPos02[i - 4] = gradient.colorKeys[i].time; |
| | 82 | | } |
| | 83 | | } |
| 0 | 84 | | Vector4 pos01 = new Vector4(tempPos01[0], tempPos01[1], tempPos01[2], tempPos01[3]); |
| 0 | 85 | | Vector4 pos02 = new Vector4(tempPos02[0], tempPos02[1], tempPos02[2], tempPos02[3]); |
| | 86 | |
|
| 0 | 87 | | targetMat.SetVector("_GradientPositions01", pos01); |
| 0 | 88 | | targetMat.SetVector("_GradientPositions02", pos02); |
| 0 | 89 | | } |
| | 90 | | } |