public void Set(string text = null, float?size = null, float?leading = null, float?tracking = null, float?paragraphSpacing = null, TTextAlignment?alignement = null, float?wordWrap = null) { Text = text ?? Text; Size = size ?? Size; Leading = leading ?? Leading; Tracking = tracking ?? Tracking; ParagraphSpacing = paragraphSpacing ?? ParagraphSpacing; Alignment = alignement ?? Alignment; WordWrap = wordWrap ?? WordWrap; }
public void Set(string text = null, float? size = null, float? leading = null, float? tracking = null, float? paragraphSpacing = null, TTextAlignment? alignement = null, float? wordWrap = null) { Text = text ?? Text; Size = size ?? Size; Leading = leading ?? Leading; Tracking = tracking ?? Tracking; ParagraphSpacing = paragraphSpacing ?? ParagraphSpacing; Alignment = alignement ?? Alignment; WordWrap = wordWrap ?? WordWrap; }
public void RebuildMesh() { if (Font == null) return; _text = Text; _size = Size; _leading = Leading; _tracking = Tracking; _paragraphSpacing = ParagraphSpacing; _wordWrap = WordWrap; _alignment = Alignment; _fillMode = FillMode; _colorTopLeft = ColorTopLeft; _colorTopRight = ColorTopRight; _colorBottomLeft = ColorBottomLeft; _colorBottomRight = ColorBottomRight; _generateNormals = GenerateNormals; _stationary = Stationary; _enableClickSupport = EnableClickSupport; _currentMaterial = 0; _materialCount = GetComponent<Renderer>().sharedMaterials.Length; m_Mesh.Clear(); m_Vertices.Clear(); m_UVs.Clear(); m_UVs2.Clear(); m_Colors.Clear(); m_SubmeshTriangles = new List<int>[_materialCount]; for (int i = 0; i < _materialCount; i++) m_SubmeshTriangles[i] = new List<int>(); if (IsTextNullOrEmpty()) return; ClearGlyphBounds(); Width = 0f; Height = 0f; float cursorX = 0f, cursorY = 0f; Text = Regex.Replace(Text, @"\r\n", "\n"); string[] lines = Regex.Split(Text, @"\n"); if (WordWrap <= 0) { foreach (string line in lines) { if (Alignment == TTextAlignment.Left) cursorX = 0f; else if (Alignment == TTextAlignment.Center) cursorX = GetStringWidth(line) / -2f; else if (Alignment == TTextAlignment.Right) cursorX = -GetStringWidth(line); BlitString(line, cursorX, cursorY); if (EnableClickSupport) { AddPlaceholderGlyphBounds(); } cursorY += Font.LineHeight * Size + Leading + ParagraphSpacing; } } else { List<int> vertexPointers = new List<int>(); foreach (string line in lines) { string[] words = line.Split(' '); cursorX = 0; foreach (string w in words) { string word = w; if (Alignment == TTextAlignment.Right) word = " " + word; else word += " "; float wordWidth = GetStringWidth(word); if (cursorX + wordWidth > WordWrap) { OffsetStringPosition(vertexPointers, cursorX); vertexPointers.Clear(); cursorX = 0; cursorY += Font.LineHeight * Size + Leading; } cursorX = BlitString(word, cursorX, cursorY, vertexPointers); if (EnableClickSupport) { AddPlaceholderGlyphBounds(); } } OffsetStringPosition(vertexPointers, cursorX); vertexPointers.Clear(); cursorY += Font.LineHeight * Size + Leading + ParagraphSpacing; } } Height = cursorY; m_Mesh.vertices = m_Vertices.ToArray(); m_Mesh.uv = m_UVs.ToArray(); m_Mesh.colors = null; m_Mesh.uv2 = null; m_Mesh.normals = null; m_Mesh.subMeshCount = GetComponent<Renderer>().sharedMaterials.Length; for (int i = 0; i < m_Mesh.subMeshCount; i++) m_Mesh.SetTriangles(m_SubmeshTriangles[i].ToArray(), i); if (FillMode == TFillMode.StretchedTexture || FillMode == TFillMode.ProjectedTexture) m_Mesh.uv2 = m_UVs2.ToArray(); else m_Mesh.colors = m_Colors.ToArray(); if (GenerateNormals) { Vector3[] normals = new Vector3[m_Vertices.Count]; for (int i = 0; i < m_Vertices.Count; i++) normals[i] = new Vector3(0f, 0f, -1f); m_Mesh.normals = normals; } m_Mesh.RecalculateBounds(); RefreshColliders(); }
public void RebuildMesh() { if (Font == null) { return; } _text = Text; _size = Size; _leading = Leading; _tracking = Tracking; _paragraphSpacing = ParagraphSpacing; _wordWrap = WordWrap; _alignment = Alignment; _fillMode = FillMode; _colorTopLeft = ColorTopLeft; _colorTopRight = ColorTopRight; _colorBottomLeft = ColorBottomLeft; _colorBottomRight = ColorBottomRight; _generateNormals = GenerateNormals; _currentMaterial = 0; _materialCount = renderer.sharedMaterials.Length; m_Mesh.Clear(); m_Vertices.Clear(); m_UVs.Clear(); m_UVs2.Clear(); m_Colors.Clear(); m_SubmeshTriangles = new List <int> [_materialCount]; for (int i = 0; i < _materialCount; i++) { m_SubmeshTriangles[i] = new List <int>(); } if (IsTextNullOrEmpty()) { return; } ClearGlyphBounds(); Width = 0f; Height = 0f; float cursorX = 0f, cursorY = 0f; Text = Regex.Replace(Text, @"\r\n", "\n"); string[] lines = Regex.Split(Text, @"\n"); if (WordWrap <= 0) { foreach (string line in lines) { if (Alignment == TTextAlignment.Left) { cursorX = 0f; } else if (Alignment == TTextAlignment.Center) { cursorX = GetStringWidth(line) / -2f; } else if (Alignment == TTextAlignment.Right) { cursorX = -GetStringWidth(line); } BlitString(line, cursorX, cursorY); AddPlaceholderGlyphBounds(); cursorY += Font.LineHeight * Size + Leading + ParagraphSpacing; } } else { List <int> vertexPointers = new List <int>(); foreach (string line in lines) { string[] words = line.Split(' '); cursorX = 0; foreach (string w in words) { string word = w; if (Alignment == TTextAlignment.Right) { word = " " + word; } else { word += " "; } float wordWidth = GetStringWidth(word); if (cursorX + wordWidth > WordWrap) { OffsetStringPosition(vertexPointers, cursorX); vertexPointers.Clear(); cursorX = 0; cursorY += Font.LineHeight * Size + Leading; } cursorX = BlitString(word, cursorX, cursorY, vertexPointers); AddPlaceholderGlyphBounds(); } OffsetStringPosition(vertexPointers, cursorX); vertexPointers.Clear(); cursorY += Font.LineHeight * Size + Leading + ParagraphSpacing; } } Height = cursorY; m_Mesh.vertices = m_Vertices.ToArray(); m_Mesh.uv = m_UVs.ToArray(); m_Mesh.colors = null; m_Mesh.uv2 = null; m_Mesh.normals = null; m_Mesh.subMeshCount = renderer.sharedMaterials.Length; for (int i = 0; i < m_Mesh.subMeshCount; i++) { m_Mesh.SetTriangles(m_SubmeshTriangles[i].ToArray(), i); } if (FillMode == TFillMode.StretchedTexture || FillMode == TFillMode.ProjectedTexture) { m_Mesh.uv2 = m_UVs2.ToArray(); } else { m_Mesh.colors = m_Colors.ToArray(); } if (GenerateNormals) { Vector3[] normals = new Vector3[m_Vertices.Count]; for (int i = 0; i < m_Vertices.Count; i++) { normals[i] = new Vector3(0f, 0f, -1f); } m_Mesh.normals = normals; } m_Mesh.RecalculateBounds(); RefreshColliders(); }