Hue Preserving Color Blending
TMP_TextInfo.cs
1 using UnityEngine;
2 using System;
3 using System.Collections;
4 using System.Collections.Generic;
5 
6 
7 namespace TMPro
8 {
12  [Serializable]
13  public class TMP_TextInfo
14  {
15  private static Vector2 k_InfinityVectorPositive = new Vector2(32767, 32767);
16  private static Vector2 k_InfinityVectorNegative = new Vector2(-32767, -32767);
17 
18  public TMP_Text textComponent;
19 
20  public int characterCount;
21  public int spriteCount;
22  public int spaceCount;
23  public int wordCount;
24  public int linkCount;
25  public int lineCount;
26  public int pageCount;
27 
28  public int materialCount;
29 
30  public TMP_CharacterInfo[] characterInfo;
31  public TMP_WordInfo[] wordInfo;
32  public TMP_LinkInfo[] linkInfo;
33  public TMP_LineInfo[] lineInfo;
34  public TMP_PageInfo[] pageInfo;
35  public TMP_MeshInfo[] meshInfo;
36 
37  private TMP_MeshInfo[] m_CachedMeshInfo;
38 
39  // Default Constructor
40  public TMP_TextInfo()
41  {
42  characterInfo = new TMP_CharacterInfo[8];
43  wordInfo = new TMP_WordInfo[16];
44  linkInfo = new TMP_LinkInfo[0];
45  lineInfo = new TMP_LineInfo[2];
46  pageInfo = new TMP_PageInfo[4];
47 
48  meshInfo = new TMP_MeshInfo[1];
49  }
50 
51 
52  public TMP_TextInfo(TMP_Text textComponent)
53  {
54  this.textComponent = textComponent;
55 
56  characterInfo = new TMP_CharacterInfo[8];
57 
58  wordInfo = new TMP_WordInfo[4];
59  linkInfo = new TMP_LinkInfo[0];
60 
61  lineInfo = new TMP_LineInfo[2];
62  pageInfo = new TMP_PageInfo[4];
63 
64  meshInfo = new TMP_MeshInfo[1];
65  meshInfo[0].mesh = textComponent.mesh;
66  materialCount = 1;
67  }
68 
69 
73  public void Clear()
74  {
75  characterCount = 0;
76  spaceCount = 0;
77  wordCount = 0;
78  linkCount = 0;
79  lineCount = 0;
80  pageCount = 0;
81  spriteCount = 0;
82 
83  for (int i = 0; i < this.meshInfo.Length; i++)
84  {
85  this.meshInfo[i].vertexCount = 0;
86  }
87  }
88 
89 
93  public void ClearMeshInfo(bool updateMesh)
94  {
95  for (int i = 0; i < this.meshInfo.Length; i++)
96  this.meshInfo[i].Clear(updateMesh);
97  }
98 
99 
103  public void ClearAllMeshInfo()
104  {
105  for (int i = 0; i < this.meshInfo.Length; i++)
106  this.meshInfo[i].Clear(true);
107  }
108 
109 
113  public void ResetVertexLayout(bool isVolumetric)
114  {
115  for (int i = 0; i < this.meshInfo.Length; i++)
116  this.meshInfo[i].ResizeMeshInfo(0, isVolumetric);
117  }
118 
119 
124  public void ClearUnusedVertices(MaterialReference[] materials)
125  {
126  for (int i = 0; i < meshInfo.Length; i++)
127  {
128  int start = 0; // materials[i].referenceCount * 4;
129  meshInfo[i].ClearUnusedVertices(start);
130  }
131  }
132 
133 
137  public void ClearLineInfo()
138  {
139  if (this.lineInfo == null)
140  this.lineInfo = new TMP_LineInfo[2];
141 
142  for (int i = 0; i < this.lineInfo.Length; i++)
143  {
144  this.lineInfo[i].characterCount = 0;
145  this.lineInfo[i].spaceCount = 0;
146  this.lineInfo[i].wordCount = 0;
147  this.lineInfo[i].controlCharacterCount = 0;
148  this.lineInfo[i].width = 0;
149 
150  this.lineInfo[i].ascender = k_InfinityVectorNegative.x;
151  this.lineInfo[i].descender = k_InfinityVectorPositive.x;
152 
153  this.lineInfo[i].lineExtents.min = k_InfinityVectorPositive;
154  this.lineInfo[i].lineExtents.max = k_InfinityVectorNegative;
155 
156  this.lineInfo[i].maxAdvance = 0;
157  //this.lineInfo[i].maxScale = 0;
158 
159  }
160  }
161 
162 
168  {
169  if (m_CachedMeshInfo == null || m_CachedMeshInfo.Length != meshInfo.Length)
170  {
171  m_CachedMeshInfo = new TMP_MeshInfo[meshInfo.Length];
172 
173  // Initialize all the vertex data arrays
174  for (int i = 0; i < m_CachedMeshInfo.Length; i++)
175  {
176  int length = meshInfo[i].vertices.Length;
177 
178  m_CachedMeshInfo[i].vertices = new Vector3[length];
179  m_CachedMeshInfo[i].uvs0 = new Vector2[length];
180  m_CachedMeshInfo[i].uvs2 = new Vector2[length];
181  m_CachedMeshInfo[i].colors32 = new Color32[length];
182 
183  //m_CachedMeshInfo[i].normals = new Vector3[length];
184  //m_CachedMeshInfo[i].tangents = new Vector4[length];
185  //m_CachedMeshInfo[i].triangles = new int[meshInfo[i].triangles.Length];
186  }
187  }
188 
189  for (int i = 0; i < m_CachedMeshInfo.Length; i++)
190  {
191  int length = meshInfo[i].vertices.Length;
192 
193  if (m_CachedMeshInfo[i].vertices.Length != length)
194  {
195  m_CachedMeshInfo[i].vertices = new Vector3[length];
196  m_CachedMeshInfo[i].uvs0 = new Vector2[length];
197  m_CachedMeshInfo[i].uvs2 = new Vector2[length];
198  m_CachedMeshInfo[i].colors32 = new Color32[length];
199 
200  //m_CachedMeshInfo[i].normals = new Vector3[length];
201  //m_CachedMeshInfo[i].tangents = new Vector4[length];
202  //m_CachedMeshInfo[i].triangles = new int[meshInfo[i].triangles.Length];
203  }
204 
205 
206  // Only copy the primary vertex data
207  Array.Copy(meshInfo[i].vertices, m_CachedMeshInfo[i].vertices, length);
208  Array.Copy(meshInfo[i].uvs0, m_CachedMeshInfo[i].uvs0, length);
209  Array.Copy(meshInfo[i].uvs2, m_CachedMeshInfo[i].uvs2, length);
210  Array.Copy(meshInfo[i].colors32, m_CachedMeshInfo[i].colors32, length);
211 
212  //Array.Copy(meshInfo[i].normals, m_CachedMeshInfo[i].normals, length);
213  //Array.Copy(meshInfo[i].tangents, m_CachedMeshInfo[i].tangents, length);
214  //Array.Copy(meshInfo[i].triangles, m_CachedMeshInfo[i].triangles, meshInfo[i].triangles.Length);
215  }
216 
217  return m_CachedMeshInfo;
218  }
219 
220 
221 
228  public static void Resize<T> (ref T[] array, int size)
229  {
230  // Allocated to the next power of two
231  int newSize = size > 1024 ? size + 256 : Mathf.NextPowerOfTwo(size);
232 
233  Array.Resize(ref array, newSize);
234  }
235 
236 
244  public static void Resize<T>(ref T[] array, int size, bool isBlockAllocated)
245  {
246  //if (size <= array.Length) return;
247 
248  if (isBlockAllocated) size = size > 1024 ? size + 256 : Mathf.NextPowerOfTwo(size);
249 
250  if (size == array.Length) return;
251 
252  Array.Resize(ref array, size);
253  }
254 
255  }
256 }
static void Resize< T >(ref T[] array, int size)
Function to resize any of the structure contained in the TMP_TextInfo class.
void ClearUnusedVertices()
Function to clear the vertices while preserving the Triangles, Normals and Tangents.
Structure which contains information about the individual lines of text.
Definition: TMP_LineInfo.cs:7
void ClearUnusedVertices(MaterialReference[] materials)
Function used to mark unused vertices as degenerate.
Class which contains information about every element contained within the text object.
Definition: TMP_TextInfo.cs:13
void ResetVertexLayout(bool isVolumetric)
Base class which contains common properties and functions shared between the TextMeshPro and TextMesh...
Definition: TMP_Text.cs:110
void ClearLineInfo()
Function to clear and initialize the lineInfo array.
TMP_MeshInfo [] CopyMeshInfoVertexData()
Function to copy the MeshInfo Arrays and their primary vertex data content.
Structure containing information about the individual words contained in the text object.
void Clear()
Function to clear the counters of the text object.
Definition: TMP_TextInfo.cs:73
Structure which contains the vertex attributes (geometry) of the text object.
Definition: TMP_MeshInfo.cs:15
TMP custom data type to represent 32 bit characters.
void ClearAllMeshInfo()
Function to clear the content of all the MeshInfo arrays while preserving their Triangles,...
virtual Mesh mesh
The mesh used by the font asset and material assigned to the text object.
Definition: TMP_Text.cs:1089
void ClearMeshInfo(bool updateMesh)
Function to clear the content of the MeshInfo array while preserving the Triangles,...
Definition: TMP_TextInfo.cs:93