Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

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

TextGenerator

Namespace: UnityEngine

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!"); }

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!'))

Variables

characterCountThe number of characters that have been generated.
charactersArray of generated characters.
extentsExtends of generated text area.
lineCountNumber of text lines generated.
linesInformation about each generated text line.
rectExtentsExtents of the generated text in rect format.
vertexCountNumber of vertices generated.
vertsArray of generated vertices.

Constructors

TextGeneratorCreate a TextGenerator.

Functions

GetCharactersPopulate the given array with UICharInfo.
GetLinesPopulate the given array with UILineInfo.
GetVertsPopulate the given array with UIVertex.
InvalidateMark the text generator as invalid. This will force a full text generation the next time Populate is called.
PopulateWill generate the vertices and other data for the given string with the given settings.