Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
InnerBevel.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using UnityEngine;
3using UnityEngine.UI;
4
5[AddComponentMenu("UI/ToJ Effects/Inner Bevel", 19)]
6[DisallowMultipleComponent]
7[RequireComponent(typeof(Text))]
8public class InnerBevel : BaseMeshEffect, IMaterialModifier
9{
10 public enum ColorMode
11 {
15 }
16
17 [SerializeField]
19
20 [SerializeField]
22
23 [SerializeField]
25
26 [SerializeField]
27 public Color m_ShadowColor = Color.black;
28
29 [SerializeField]
30 private Vector2 m_BevelDirectionAndDepth = new Vector2(1f, 1f);
31
33
35
36 private List<UIVertex> m_Verts = new List<UIVertex>();
37
39 {
40 get
41 {
43 }
44 set
45 {
47 if (base.graphic != null)
48 {
49 base.graphic.SetVerticesDirty();
50 }
51 }
52 }
53
55 {
56 get
57 {
58 return m_HighlightColor;
59 }
60 set
61 {
62 m_HighlightColor = value;
63 if (base.graphic != null)
64 {
65 base.graphic.SetVerticesDirty();
66 }
67 }
68 }
69
71 {
72 get
73 {
74 return m_ShadowColorMode;
75 }
76 set
77 {
78 m_ShadowColorMode = value;
79 if (base.graphic != null)
80 {
81 base.graphic.SetVerticesDirty();
82 }
83 }
84 }
85
87 {
88 get
89 {
90 return m_ShadowColor;
91 }
92 set
93 {
94 m_ShadowColor = value;
95 if (base.graphic != null)
96 {
97 base.graphic.SetVerticesDirty();
98 }
99 }
100 }
101
103 {
104 get
105 {
107 }
108 set
109 {
110 if (!(m_BevelDirectionAndDepth == value))
111 {
113 if (base.graphic != null)
114 {
115 base.graphic.SetVerticesDirty();
116 }
117 }
118 }
119 }
120
121 protected InnerBevel()
122 {
123 }
124
125 protected override void Start()
126 {
127 if (base.graphic != null)
128 {
129 base.graphic.SetMaterialDirty();
130 }
131 }
132
133 public override void ModifyMesh(VertexHelper vh)
134 {
135 if (!IsActive())
136 {
137 return;
138 }
139 vh.GetUIVertexStream(m_Verts);
140 int count = m_Verts.Count;
141 for (int i = 0; i < count; i += 6)
142 {
143 UIVertex value = m_Verts[i];
144 Vector2 vector = (m_Verts[i + 1].uv0 - m_Verts[i].uv0).normalized;
145 Vector2 vector2 = (m_Verts[i + 1].uv0 - m_Verts[i + 2].uv0).normalized;
146 Vector4 tangent = vector;
147 tangent.z = vector2.x;
148 tangent.w = vector2.y;
149 value.tangent = tangent;
150 if (value.uv1 == Vector4.zero)
151 {
152 value.uv1 = new Vector2(1f, 1f);
153 }
154 m_Verts[i] = value;
155 for (int j = 1; j < 6; j++)
156 {
157 value = m_Verts[i + j];
158 value.tangent = m_Verts[i].tangent;
159 if (value.uv1 == Vector4.zero)
160 {
161 value.uv1 = new Vector2(1f, 1f);
162 }
163 m_Verts[i + j] = value;
164 }
165 }
166 vh.Clear();
167 vh.AddUIVertexTriangleStream(m_Verts);
168 }
169
170 private void Update()
171 {
172 if (m_NeedsToSetMaterialDirty && base.graphic != null)
173 {
174 base.graphic.SetMaterialDirty();
175 }
176 }
177
178 public virtual Material GetModifiedMaterial(Material baseMaterial)
179 {
180 if (!IsActive())
181 {
182 return baseMaterial;
183 }
184 if (baseMaterial.shader != Shader.Find("Text Effects/Fancy Text"))
185 {
186 Debug.Log("\"" + base.gameObject.name + "\" doesn't have the \"Fancy Text\" shader applied. Please use it if you are using the \"Inner Bevel\" effect.");
187 return baseMaterial;
188 }
189 if (m_ModifiedMaterial == null)
190 {
191 m_ModifiedMaterial = new Material(baseMaterial);
192 }
193 m_ModifiedMaterial.CopyPropertiesFromMaterial(baseMaterial);
194 m_ModifiedMaterial.name = baseMaterial.name + " with IB";
195 m_ModifiedMaterial.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
196 m_ModifiedMaterial.shaderKeywords = baseMaterial.shaderKeywords;
197 m_ModifiedMaterial.CopyPropertiesFromMaterial(baseMaterial);
198 m_ModifiedMaterial.EnableKeyword("_USEBEVEL_ON");
199 m_ModifiedMaterial.SetColor("_HighlightColor", highlightColor);
200 m_ModifiedMaterial.SetColor("_ShadowColor", shadowColor);
201 m_ModifiedMaterial.SetVector("_HighlightOffset", bevelDirectionAndDepth / 500f);
202 m_ModifiedMaterial.SetInt("_HighlightColorMode", (int)highlightColorMode);
203 m_ModifiedMaterial.SetInt("_ShadowColorMode", (int)shadowColorMode);
205 return m_ModifiedMaterial;
206 }
207}
Vector2 m_BevelDirectionAndDepth
Definition: InnerBevel.cs:30
Color shadowColor
Definition: InnerBevel.cs:87
Material m_ModifiedMaterial
Definition: InnerBevel.cs:34
override void ModifyMesh(VertexHelper vh)
Definition: InnerBevel.cs:133
Vector2 bevelDirectionAndDepth
Definition: InnerBevel.cs:103
override void Start()
Definition: InnerBevel.cs:125
ColorMode m_HighlightColorMode
Definition: InnerBevel.cs:18
Color highlightColor
Definition: InnerBevel.cs:55
virtual Material GetModifiedMaterial(Material baseMaterial)
Definition: InnerBevel.cs:178
void Update()
Definition: InnerBevel.cs:170
ColorMode shadowColorMode
Definition: InnerBevel.cs:71
Color m_ShadowColor
Definition: InnerBevel.cs:27
ColorMode m_ShadowColorMode
Definition: InnerBevel.cs:24
ColorMode highlightColorMode
Definition: InnerBevel.cs:39
List< UIVertex > m_Verts
Definition: InnerBevel.cs:36
Color m_HighlightColor
Definition: InnerBevel.cs:21
bool m_NeedsToSetMaterialDirty
Definition: InnerBevel.cs:32