Namespace: UnityEngine
Class that can be used to generate text for rendering.
Caches vertices, character info, and line info for memory friendlyness.
var font : Font;function Start () { var settings = new TextGenerationSettings(); settings.anchor = TextAnchor.MiddleCenter; settings.color = Color.red; settings.extents = new Vector2(500f, 200f); settings.pivot = Vector2.zero; settings.richText = true; settings.font = font; settings.size = 32; settings.style = FontStyle.Normal; settings.wrapMode = TextWrapMode.Wrap; var generator = new TextGenerator(); generator.Populate("I am a string", settings); Debug.Log("I generated: " + generator.vertexCount + " verts!"); }
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { public Font font; void Start() { TextGenerationSettings settings = new TextGenerationSettings(); settings.anchor = TextAnchor.MiddleCenter; settings.color = Color.red; settings.extents = new Vector2(500.0F, 200.0F); settings.pivot = Vector2.zero; settings.richText = true; settings.font = font; settings.size = 32; settings.style = FontStyle.Normal; settings.wrapMode = TextWrapMode.Wrap; TextGenerator generator = new TextGenerator(); generator.Populate("I am a string", settings); Debug.Log("I generated: " + generator.vertexCount + " verts!"); } }
import UnityEngine import System.Collections public class ExampleClass(MonoBehaviour): public font as Font def Start() as void: settings as TextGenerationSettings = TextGenerationSettings() settings.anchor = TextAnchor.MiddleCenter settings.color = Color.red settings.extents = Vector2(500.0F, 200.0F) settings.pivot = Vector2.zero settings.richText = true settings.font = font settings.size = 32 settings.style = FontStyle.Normal settings.wrapMode = TextWrapMode.Wrap generator as TextGenerator = TextGenerator() generator.Populate('I am a string', settings) Debug.Log((('I generated: ' + generator.vertexCount) + ' verts!'))
characterCount | The number of characters that have been generated. |
characters | Array of generated characters. |
extents | Extends of generated text area. |
lineCount | Number of text lines generated. |
lines | Information about each generated text line. |
rectExtents | Extents of the generated text in rect format. |
vertexCount | Number of vertices generated. |
verts | Array of generated vertices. |
TextGenerator | Create a TextGenerator. |
GetCharacters | Populate the given array with UICharInfo. |
GetLines | Populate the given array with UILineInfo. |
GetVerts | Populate the given array with UIVertex. |
Invalidate | Mark the text generator as invalid. This will force a full text generation the next time Populate is called. |
Populate | Will generate the vertices and other data for the given string with the given settings. |