Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
GradientEffect.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using UnityEngine;
3using UnityEngine.UI;
4
5[AddComponentMenu("UI/Effects/GradientEffect")]
6public class GradientEffect : BaseMeshEffect
7{
9
11
12 public bool overwriteAllColor;
13
14 public Color vertex1 = Color.white;
15
16 public Color vertex2 = Color.black;
17
18 private Graphic _targetGraphic;
19
20 private Graphic targetGraphic
21 {
22 get
23 {
24 if (_targetGraphic == null)
25 {
26 _targetGraphic = GetComponent<Graphic>();
27 }
28 return _targetGraphic;
29 }
30 }
31
32 public override void ModifyMesh(VertexHelper vh)
33 {
34 if (IsActive())
35 {
36 List<UIVertex> list = new List<UIVertex>();
37 vh.GetUIVertexStream(list);
38 ModifyVertices(list);
39 vh.Clear();
40 vh.AddUIVertexTriangleStream(list);
41 }
42 }
43
44 public void ModifyVertices(List<UIVertex> vertexList)
45 {
46 if (!IsActive() || vertexList.Count == 0)
47 {
48 return;
49 }
50 int count = vertexList.Count;
51 UIVertex uIVertex = vertexList[0];
52 if (gradientMode == GradientMode.Global)
53 {
54 if (gradientDir == GradientDir.DiagonalLeftToRight || gradientDir == GradientDir.DiagonalRightToLeft)
55 {
56 gradientDir = GradientDir.Vertical;
57 }
58 float num = ((gradientDir == GradientDir.Vertical) ? vertexList[vertexList.Count - 1].position.y : vertexList[vertexList.Count - 1].position.x);
59 float num2 = ((gradientDir == GradientDir.Vertical) ? vertexList[0].position.y : vertexList[0].position.x) - num;
60 for (int i = 0; i < count; i++)
61 {
62 uIVertex = vertexList[i];
63 if (overwriteAllColor || !(uIVertex.color != targetGraphic.color))
64 {
65 ref Color32 color = ref uIVertex.color;
66 color *= Color.Lerp(vertex2, vertex1, (((gradientDir == GradientDir.Vertical) ? uIVertex.position.y : uIVertex.position.x) - num) / num2);
67 vertexList[i] = uIVertex;
68 }
69 }
70 return;
71 }
72 for (int j = 0; j < count; j++)
73 {
74 uIVertex = vertexList[j];
75 if (overwriteAllColor || CompareCarefully(uIVertex.color, targetGraphic.color))
76 {
77 switch (gradientDir)
78 {
79 case GradientDir.Vertical:
80 {
81 ref Color32 color4 = ref uIVertex.color;
82 color4 *= ((j % 4 == 0 || (j - 1) % 4 == 0) ? vertex1 : vertex2);
83 break;
84 }
85 case GradientDir.Horizontal:
86 {
87 ref Color32 color5 = ref uIVertex.color;
88 color5 *= ((j % 4 == 0 || (j - 3) % 4 == 0) ? vertex1 : vertex2);
89 break;
90 }
91 case GradientDir.DiagonalLeftToRight:
92 {
93 ref Color32 color3 = ref uIVertex.color;
94 color3 *= ((j % 4 == 0) ? vertex1 : (((j - 2) % 4 == 0) ? vertex2 : Color.Lerp(vertex2, vertex1, 0.5f)));
95 break;
96 }
97 case GradientDir.DiagonalRightToLeft:
98 {
99 ref Color32 color2 = ref uIVertex.color;
100 color2 *= (((j - 1) % 4 == 0) ? vertex1 : (((j - 3) % 4 == 0) ? vertex2 : Color.Lerp(vertex2, vertex1, 0.5f)));
101 break;
102 }
103 }
104 vertexList[j] = uIVertex;
105 }
106 }
107 }
108
109 private bool CompareCarefully(Color col1, Color col2)
110 {
111 if (Mathf.Abs(col1.r - col2.r) < 0.003f && Mathf.Abs(col1.g - col2.g) < 0.003f && Mathf.Abs(col1.b - col2.b) < 0.003f && Mathf.Abs(col1.a - col2.a) < 0.003f)
112 {
113 return true;
114 }
115 return false;
116 }
117}
GradientDir
Definition: GradientDir.cs:2
GradientMode
Definition: GradientMode.cs:2
GradientMode gradientMode
GradientDir gradientDir
override void ModifyMesh(VertexHelper vh)
Graphic _targetGraphic
bool CompareCarefully(Color col1, Color col2)
Graphic targetGraphic
void ModifyVertices(List< UIVertex > vertexList)