void InitInstance() { if (data != null && data.font != null) { _fontInst = data.font.inst; _fontInst.InitDictionary(); } }
public void Init() { if (_fontInst && ((updateFlags & UpdateFlags.UpdateBuffers) != 0 || mesh == null)) { _fontInst.InitDictionary(); FormatText(); var geomData = tk2dTextGeomGen.Data(data, _fontInst, _formattedText); // volatile data int numVertices; int numIndices; tk2dTextGeomGen.GetTextMeshGeomDesc(out numVertices, out numIndices, geomData); vertices = new Vector3[numVertices]; uvs = new Vector2[numVertices]; colors = new Color32[numVertices]; untintedColors = new Color32[numVertices]; if (_fontInst.textureGradients) { uv2 = new Vector2[numVertices]; } int[] triangles = new int[numIndices]; int target = tk2dTextGeomGen.SetTextMeshGeom(vertices, uvs, uv2, untintedColors, 0, geomData); if (!_fontInst.isPacked) { Color32 topColor = data.color; Color32 bottomColor = data.useGradient ? data.color2 : data.color; for (int i = 0; i < numVertices; ++i) { Color32 c = ((i % 4) < 2) ? topColor : bottomColor; byte red = (byte)(((int)untintedColors[i].r * (int)c.r) / 255); byte green = (byte)(((int)untintedColors[i].g * (int)c.g) / 255); byte blue = (byte)(((int)untintedColors[i].b * (int)c.b) / 255); byte alpha = (byte)(((int)untintedColors[i].a * (int)c.a) / 255); if (_fontInst.premultipliedAlpha) { red = (byte)(((int)red * (int)alpha) / 255); green = (byte)(((int)green * (int)alpha) / 255); blue = (byte)(((int)blue * (int)alpha) / 255); } colors[i] = new Color32(red, green, blue, alpha); } } else { colors = untintedColors; } tk2dTextGeomGen.SetTextMeshIndices(triangles, 0, 0, geomData, target); if (mesh == null) { if (meshFilter == null) { meshFilter = GetComponent <MeshFilter>(); } mesh = new Mesh(); #if !UNITY_3_5 mesh.MarkDynamic(); #endif mesh.hideFlags = HideFlags.DontSave; meshFilter.mesh = mesh; } else { mesh.Clear(); } mesh.vertices = vertices; mesh.uv = uvs; if (font.textureGradients) { mesh.uv2 = uv2; } mesh.triangles = triangles; mesh.colors32 = colors; mesh.RecalculateBounds(); mesh.bounds = tk2dBaseSprite.AdjustedMeshBounds(mesh.bounds, data.renderLayer); updateFlags = UpdateFlags.UpdateNone; } }
public void Init() { if (_fontInst && ((updateFlags & UpdateFlags.UpdateBuffers) != 0 || mesh == null)) { _fontInst.InitDictionary(); FormatText(); 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) { if (!_fontInst.isPacked) { 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; } if (!_fontInst.isPacked) { colors[i * 4 + 0] = colors[i * 4 + 1] = topColor; colors[i * 4 + 2] = colors[i * 4 + 3] = bottomColor; } else { colors[i * 4 + 0] = colors[i * 4 + 1] = colors[i * 4 + 2] = colors[i * 4 + 3] = Color.clear; } 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; } }