可用于为渲染生成文本的类。
缓存顶点、字符信息和行信息以节约内存。
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { public Font font; void Start() { TextGenerationSettings settings = new TextGenerationSettings(); settings.textAnchor = TextAnchor.MiddleCenter; settings.color = Color.red; settings.generationExtents = new Vector2(500.0F, 200.0F); settings.pivot = Vector2.zero; settings.richText = true; settings.font = font; settings.fontSize = 32; settings.fontStyle = FontStyle.Normal; settings.verticalOverflow = VerticalWrapMode.Overflow; TextGenerator generator = new TextGenerator(); generator.Populate("I am a string", settings); Debug.Log("I generated: " + generator.vertexCount + " verts!"); } }
| characterCount | 已生成的字符数。 |
| characterCountVisible | 已生成且包含在可见行中的字符数。 |
| characters | 已生成字符的数组。 |
| fontSizeUsedForBestFit | 如果使用最佳匹配模式找到的字体大小。 |
| lineCount | 已生成文本行的数量。 |
| lines | 有关每个已生成文本行的信息。 |
| rectExtents | 矩形格式中已生成文本的范围。 |
| vertexCount | 已生成顶点的数量。 |
| verts | 已生成顶点的数组。 |
| TextGenerator | 创建一个 TextGenerator。 |
| GetCharacters | 使用 UICharInfo 填充给定列表。 |
| GetCharactersArray | 返回当前 UICharInfo。 |
| GetLines | 使用 UILineInfo 填充给定列表。 |
| GetLinesArray | 返回当前 UILineInfo。 |
| GetPreferredHeight | 给定字符串和设置,返回用于容纳此文本的容器的首选高度。 |
| GetPreferredWidth | 给定字符串和设置,返回用于容纳此文本的容器的首选宽度。 |
| GetVertices | 使用生成的顶点填充给定列表。 |
| GetVerticesArray | 返回当前 UIVertex 数组。 |
| Invalidate | 标记文本生成器为无效。这将强制在下一次调用 Populate 时进行完整文本生成。 |
| Populate | 将使用给定设置针对给定字符串生成顶点和其他数据。 |
| PopulateWithErrors | 将使用给定设置针对给定字符串生成顶点和其他数据。 |