Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
OverlayTexture.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using UnityEngine;
3using UnityEngine.UI;
4
5[AddComponentMenu("UI/ToJ Effects/Overlay Texture", 18)]
6[DisallowMultipleComponent]
7[RequireComponent(typeof(Text))]
8public class OverlayTexture : BaseMeshEffect, IMaterialModifier
9{
10 public enum TextureMode
11 {
12 Local,
15 }
16
17 public enum ColorMode
18 {
22 }
23
24 [SerializeField]
26
27 [SerializeField]
29
30 [SerializeField]
31 public Texture2D m_OverlayTexture;
32
34
36
37 private List<UIVertex> m_Verts = new List<UIVertex>();
38
40 {
41 get
42 {
43 return m_TextureMode;
44 }
45 set
46 {
47 m_TextureMode = value;
48 if (base.graphic != null)
49 {
50 base.graphic.SetVerticesDirty();
51 }
52 }
53 }
54
56 {
57 get
58 {
59 return m_ColorMode;
60 }
61 set
62 {
63 m_ColorMode = value;
64 if (base.graphic != null)
65 {
66 base.graphic.SetVerticesDirty();
67 }
68 }
69 }
70
71 public Texture2D overlayTexture
72 {
73 get
74 {
75 return m_OverlayTexture;
76 }
77 set
78 {
79 m_OverlayTexture = value;
80 if (base.graphic != null)
81 {
82 base.graphic.SetVerticesDirty();
83 }
84 }
85 }
86
87 protected OverlayTexture()
88 {
89 }
90
91 protected override void Start()
92 {
93 if (base.graphic != null)
94 {
95 base.graphic.SetMaterialDirty();
96 }
97 }
98
99 public override void ModifyMesh(VertexHelper vh)
100 {
101 if (!IsActive())
102 {
103 return;
104 }
105 vh.GetUIVertexStream(m_Verts);
106 int count = m_Verts.Count;
107 if (m_Verts.Count == 0)
108 {
109 return;
110 }
111 if (textureMode == TextureMode.GlobalTextArea || textureMode == TextureMode.GlobalFullRect)
112 {
113 Vector2 zero = Vector2.zero;
114 Vector2 zero2 = Vector2.zero;
115 if (textureMode == TextureMode.GlobalFullRect)
116 {
117 Rect rect = GetComponent<RectTransform>().rect;
118 zero = new Vector2(rect.xMin, rect.yMax);
119 zero2 = new Vector2(rect.xMax, rect.yMin);
120 }
121 else
122 {
123 zero = m_Verts[0].position;
124 zero2 = m_Verts[m_Verts.Count - 1].position;
125 for (int i = 0; i < m_Verts.Count; i++)
126 {
127 if (m_Verts[i].position.x < zero.x)
128 {
129 zero.x = m_Verts[i].position.x;
130 }
131 if (m_Verts[i].position.y > zero.y)
132 {
133 zero.y = m_Verts[i].position.y;
134 }
135 if (m_Verts[i].position.x > zero2.x)
136 {
137 zero2.x = m_Verts[i].position.x;
138 }
139 if (m_Verts[i].position.y < zero2.y)
140 {
141 zero2.y = m_Verts[i].position.y;
142 }
143 }
144 }
145 float num = zero.y - zero2.y;
146 float num2 = zero2.x - zero.x;
147 for (int j = 0; j < count; j++)
148 {
149 UIVertex value = m_Verts[j];
150 value.uv1 = new Vector2(1f + (value.position.x - zero.x) / num2, 2f - (zero.y - value.position.y) / num);
151 m_Verts[j] = value;
152 }
153 }
154 else
155 {
156 for (int k = 0; k < count; k++)
157 {
158 UIVertex value = m_Verts[k];
159 value.uv1 = new Vector2(1 + ((k % 6 != 0 && k % 6 != 5 && k % 6 != 4) ? 1 : 0), 1 + ((k % 6 != 2 && k % 6 != 3 && k % 6 != 4) ? 1 : 0));
160 m_Verts[k] = value;
161 }
162 }
163 vh.Clear();
164 vh.AddUIVertexTriangleStream(m_Verts);
165 }
166
167 private void Update()
168 {
169 if (m_NeedsToSetMaterialDirty && base.graphic != null)
170 {
171 base.graphic.SetMaterialDirty();
172 }
173 }
174
175 public virtual Material GetModifiedMaterial(Material baseMaterial)
176 {
177 if (!IsActive())
178 {
179 return baseMaterial;
180 }
181 if (baseMaterial.shader != Shader.Find("Text Effects/Fancy Text"))
182 {
183 Debug.Log("\"" + base.gameObject.name + "\" doesn't have the \"Fancy Text\" shader applied. Please use it if you are using the \"Overlay Texture\" effect.");
184 return baseMaterial;
185 }
186 if (m_ModifiedMaterial == null)
187 {
188 m_ModifiedMaterial = new Material(baseMaterial);
189 }
190 m_ModifiedMaterial.CopyPropertiesFromMaterial(baseMaterial);
191 m_ModifiedMaterial.name = baseMaterial.name + " with OT";
192 m_ModifiedMaterial.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
193 m_ModifiedMaterial.shaderKeywords = baseMaterial.shaderKeywords;
194 m_ModifiedMaterial.CopyPropertiesFromMaterial(baseMaterial);
195 m_ModifiedMaterial.EnableKeyword("_USEOVERLAYTEXTURE_ON");
196 m_ModifiedMaterial.SetTexture("_OverlayTex", overlayTexture);
197 m_ModifiedMaterial.SetInt("_OverlayTextureColorMode", (int)colorMode);
199 return m_ModifiedMaterial;
200 }
201}
override void ModifyMesh(VertexHelper vh)
Texture2D m_OverlayTexture
Texture2D overlayTexture
virtual Material GetModifiedMaterial(Material baseMaterial)
List< UIVertex > m_Verts
override void Start()
TextureMode m_TextureMode
ColorMode colorMode
ColorMode m_ColorMode
bool m_NeedsToSetMaterialDirty
Material m_ModifiedMaterial
TextureMode textureMode