Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

TextGenerator

Namespace: UnityEngine

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

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!"); }
no example available in C#
no example available in Boo

Variables

characterCount The number of characters that have been generated.
characterCountVisible The number of characters that have been generated and are included in the visible lines.
characters Array of generated characters.
fontSizeUsedForBestFit The size of the font that was found if using best fit mode.
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.

Constructors

TextGenerator Create a TextGenerator.

Functions

GetCharacters Populate the given List with UICharInfo.
GetCharactersArray Returns the current UICharInfo.
GetLines Populate the given list with UILineInfo.
GetLinesArray Returns the current UILineInfo.
GetPreferredHeight Given a string and settings, returns the preferred height for a container that would hold this text.
GetPreferredWidth Given a string and settings, returns the preferred width for a container that would hold this text.
GetVertices Populate the given list with generated Vertices.
GetVerticesArray Returns the current UILineInfo.
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.