public void Init()
{
if (_fontInst && ((updateFlags & UpdateFlags.UpdateBuffers) != 0 || mesh == null))
{
FormatText();
_fontInst.InitDictionary();
Color topColor = _color;
Color bottomColor = _useGradient?_color2:_color;
// volatile data
vertices = new Vector3[_maxChars * 4];
uvs = new Vector2[_maxChars * 4];
colors = new Color[_maxChars * 4];
if (_fontInst.textureGradients)
{
uv2 = new Vector2[_maxChars * 4];
}
int[] triangles = new int[_maxChars * 6];
int target = FillTextData();
for (int i = 0; i < target; ++i)
{
colors[i * 4 + 0] = colors[i * 4 + 1] = topColor;
colors[i * 4 + 2] = colors[i * 4 + 3] = bottomColor;
triangles[i * 6 + 0] = i * 4 + 0;
triangles[i * 6 + 1] = i * 4 + 1;
triangles[i * 6 + 2] = i * 4 + 3;
triangles[i * 6 + 3] = i * 4 + 2;
triangles[i * 6 + 4] = i * 4 + 0;
triangles[i * 6 + 5] = i * 4 + 3;
}
for (int i = target; i < _maxChars; ++i)
{
vertices[i * 4 + 0] = vertices[i * 4 + 1] = vertices[i * 4 + 2] = vertices[i * 4 + 3] = Vector3.zero;
uvs[i * 4 + 0] = uvs[i * 4 + 1] = uvs[i * 4 + 2] = uvs[i * 4 + 3] = Vector2.zero;
if (_fontInst.textureGradients)
{
uv2[i * 4 + 0] = uv2[i * 4 + 1] = uv2[i * 4 + 2] = uv2[i * 4 + 3] = Vector2.zero;
}
colors[i * 4 + 0] = colors[i * 4 + 1] = topColor;
colors[i * 4 + 2] = colors[i * 4 + 3] = bottomColor;
triangles[i * 6 + 0] = i * 4 + 0;
triangles[i * 6 + 1] = i * 4 + 1;
triangles[i * 6 + 2] = i * 4 + 3;
triangles[i * 6 + 3] = i * 4 + 2;
triangles[i * 6 + 4] = i * 4 + 0;
triangles[i * 6 + 5] = i * 4 + 3;
}
if (mesh == null)
{
if (meshFilter == null)
meshFilter = GetComponent<MeshFilter>();
mesh = new Mesh();
mesh.hideFlags = HideFlags.DontSave;
meshFilter.mesh = mesh;
}
else
{
mesh.Clear();
}
mesh.vertices = vertices;
mesh.uv = uvs;
if (font.textureGradients)
{
mesh.uv1 = uv2;
}
mesh.triangles = triangles;
mesh.colors = colors;
mesh.RecalculateBounds();
updateFlags = UpdateFlags.UpdateNone;
}
}