Class TextMeshPro
Inheritance
Inherited Members
Namespace: TMPro
Assembly: Unity.TextMeshPro.dll
Syntax
[DisallowMultipleComponent]
[RequireComponent(typeof(MeshRenderer))]
[AddComponentMenu("Mesh/TextMeshPro - Text")]
[ExecuteAlways]
[HelpURL("https://docs.unity3d.com/Packages/com.unity.ugui@2.0/manual/TextMeshPro/index.html")]
public class TextMeshPro : TMP_Text, ICanvasElement, IClippable, IMaskable, IMaterialModifier, ILayoutElement
Properties
autoSizeTextContainer
Determines if the size of the text container will be adjusted to fit the text object when it is first created.
Declaration
public override bool autoSizeTextContainer { get; set; }
Property Value
Type | Description |
---|---|
bool |
Overrides
maskType
Sets the mask type
Declaration
public MaskingTypes maskType { get; set; }
Property Value
Type | Description |
---|---|
MaskingTypes |
mesh
Returns the mesh assigned to the text object.
Declaration
public override Mesh mesh { get; }
Property Value
Type | Description |
---|---|
Mesh |
Overrides
meshFilter
Returns the Mesh Filter of the text object.
Declaration
public MeshFilter meshFilter { get; }
Property Value
Type | Description |
---|---|
MeshFilter |
renderer
Returns the rendered assigned to the text object.
Declaration
public Renderer renderer { get; }
Property Value
Type | Description |
---|---|
Renderer |
sortingLayerID
Sets the Renderer's sorting Layer ID
Declaration
public int sortingLayerID { get; set; }
Property Value
Type | Description |
---|---|
int |
sortingOrder
Sets the Renderer's sorting order within the assigned layer.
Declaration
public int sortingOrder { get; set; }
Property Value
Type | Description |
---|---|
int |
textContainer
Returns a reference to the Text Container
Declaration
[Obsolete("The TextContainer is now obsolete. Use the RectTransform instead.")]
public TextContainer textContainer { get; }
Property Value
Type | Description |
---|---|
TextContainer |
transform
Returns a reference to the Transform
Declaration
public Transform transform { get; }
Property Value
Type | Description |
---|---|
Transform |
Methods
Awake()
Declaration
protected override void Awake()
Overrides
CalculateLayoutInputHorizontal()
After this method is invoked, layout horizontal input properties should return up-to-date values. Children will already have up-to-date layout horizontal inputs when this methods is called.
Declaration
public void CalculateLayoutInputHorizontal()
CalculateLayoutInputVertical()
After this method is invoked, layout vertical input properties should return up-to-date values. Children will already have up-to-date layout vertical inputs when this methods is called.
Declaration
public void CalculateLayoutInputVertical()
ClearMesh(bool)
Function to clear the geometry of the Primary and Sub Text objects.
Declaration
public override void ClearMesh(bool updateMesh)
Parameters
Type | Name | Description |
---|---|---|
bool | updateMesh |
Overrides
ComputeMarginSize()
Update the margin width and height
Declaration
public override void ComputeMarginSize()
Overrides
DestroySubMeshObjects()
Destroy Sub Mesh Objects
Declaration
protected override void DestroySubMeshObjects()
Overrides
ForceMeshUpdate(bool, bool)
Function to force regeneration of the text object before its normal process time. This is useful when changes to the text object properties need to be applied immediately.
Declaration
public override void ForceMeshUpdate(bool ignoreActiveState = false, bool forceTextReparsing = false)
Parameters
Type | Name | Description |
---|---|---|
bool | ignoreActiveState | Ignore Active State of text objects. Inactive objects are ignored by default. |
bool | forceTextReparsing | Force re-parsing of the text. |
Overrides
GenerateTextMesh()
This is the main function that is responsible for creating / displaying the text.
Declaration
protected virtual void GenerateTextMesh()
GetCompoundBounds()
Method returning the compound bounds of the text object and child sub objects.
Declaration
protected override Bounds GetCompoundBounds()
Returns
Type | Description |
---|---|
Bounds |
Overrides
GetMaterial(Material)
Function called internally when a new material is assigned via the fontMaterial property.
Declaration
protected override Material GetMaterial(Material mat)
Parameters
Type | Name | Description |
---|---|---|
Material | mat |
Returns
Type | Description |
---|---|
Material |
Overrides
GetMaterials(Material[])
Method returning instances of the materials used by the text object.
Declaration
protected override Material[] GetMaterials(Material[] mats)
Parameters
Type | Name | Description |
---|---|---|
Material[] | mats |
Returns
Type | Description |
---|---|
Material[] |
Overrides
GetSharedMaterials()
Method returning an array containing the materials used by the text object.
Declaration
protected override Material[] GetSharedMaterials()
Returns
Type | Description |
---|---|
Material[] |
Overrides
GetTextContainerLocalCorners()
Method to return the local corners of the Text Container or RectTransform.
Declaration
protected override Vector3[] GetTextContainerLocalCorners()
Returns
Type | Description |
---|---|
Vector3[] |
Overrides
GetTextInfo(string)
Function used to evaluate the length of a text string.
Declaration
public override TMP_TextInfo GetTextInfo(string text)
Parameters
Type | Name | Description |
---|---|---|
string | text |
Returns
Type | Description |
---|---|
TMP_TextInfo |
Overrides
LoadFontAsset()
Method which derived classes need to override to load Font Assets.
Declaration
protected override void LoadFontAsset()
Overrides
OnDestroy()
Declaration
protected override void OnDestroy()
Overrides
OnDidApplyAnimationProperties()
Declaration
protected override void OnDidApplyAnimationProperties()
Overrides
OnDisable()
Clear references.
Declaration
protected override void OnDisable()
Overrides
OnEnable()
Mark the Graphic and the canvas as having been changed.
Declaration
protected override void OnEnable()
Overrides
OnRectTransformDimensionsChange()
This callback is called when the dimensions of an associated RectTransform change. It is always called before Awake, OnEnable, or Start. The call is also made to all child RectTransforms, regardless of whether their dimensions change (which depends on how they are anchored).
Declaration
protected override void OnRectTransformDimensionsChange()
Overrides
OnTransformParentChanged()
Declaration
protected override void OnTransformParentChanged()
Overrides
OnValidate()
Declaration
protected override void OnValidate()
Overrides
Rebuild(CanvasUpdate)
Declaration
public override void Rebuild(CanvasUpdate update)
Parameters
Type | Name | Description |
---|---|---|
CanvasUpdate | update |
Overrides
Reset()
Declaration
protected override void Reset()
Overrides
SetActiveSubMeshes(bool)
Method to Enable or Disable child SubMesh objects.
Declaration
protected override void SetActiveSubMeshes(bool state)
Parameters
Type | Name | Description |
---|---|---|
bool | state |
Overrides
SetActiveSubTextObjectRenderers(bool)
Declaration
protected void SetActiveSubTextObjectRenderers(bool state)
Parameters
Type | Name | Description |
---|---|---|
bool | state |
SetAllDirty()
Declaration
public override void SetAllDirty()
Overrides
SetCulling()
Set the culling mode on the material.
Declaration
protected override void SetCulling()
Overrides
SetFaceColor(Color32)
Function called internally to set the face color of the material. This will results in an instance of the material.
Declaration
protected override void SetFaceColor(Color32 color)
Parameters
Type | Name | Description |
---|---|---|
Color32 | color |
Overrides
SetLayoutDirty()
Declaration
public override void SetLayoutDirty()
Overrides
SetMask(MaskingTypes, Vector4)
Function used to set the mask type and coordinates in World Space
Declaration
public void SetMask(MaskingTypes type, Vector4 maskCoords)
Parameters
Type | Name | Description |
---|---|---|
MaskingTypes | type | |
Vector4 | maskCoords |
SetMask(MaskingTypes, Vector4, float, float)
Function used to set the mask type, coordinates and softness
Declaration
public void SetMask(MaskingTypes type, Vector4 maskCoords, float softnessX, float softnessY)
Parameters
Type | Name | Description |
---|---|---|
MaskingTypes | type | |
Vector4 | maskCoords | |
float | softnessX | |
float | softnessY |
SetMaterialDirty()
Schedule updating of the material used by the text object.
Declaration
public override void SetMaterialDirty()
Overrides
SetOutlineColor(Color32)
Function called internally to set the outline color of the material. This will results in an instance of the material.
Declaration
protected override void SetOutlineColor(Color32 color)
Parameters
Type | Name | Description |
---|---|---|
Color32 | color |
Overrides
SetOutlineThickness(float)
Function called internally to set the outline thickness property of the material. This will results in an instance of the material.
Declaration
protected override void SetOutlineThickness(float thickness)
Parameters
Type | Name | Description |
---|---|---|
float | thickness |
Overrides
SetShaderDepth()
Set the Render Queue and ZTest mode on the current material
Declaration
protected override void SetShaderDepth()
Overrides
SetSharedMaterial(Material)
Function called internally when a new shared material is assigned via the fontSharedMaterial property.
Declaration
protected override void SetSharedMaterial(Material mat)
Parameters
Type | Name | Description |
---|---|---|
Material | mat |
Overrides
SetSharedMaterials(Material[])
Method used to assign new materials to the text and sub text objects.
Declaration
protected override void SetSharedMaterials(Material[] materials)
Parameters
Type | Name | Description |
---|---|---|
Material[] | materials |
Overrides
SetVerticesDirty()
Schedule rebuilding of the text geometry.
Declaration
public override void SetVerticesDirty()
Overrides
UpdateFontAsset()
Declaration
public void UpdateFontAsset()
UpdateGeometry(Mesh, int)
Function to update the geometry of the main and sub text objects.
Declaration
public override void UpdateGeometry(Mesh mesh, int index)
Parameters
Type | Name | Description |
---|---|---|
Mesh | mesh | |
int | index |
Overrides
UpdateMaterial()
Declaration
protected override void UpdateMaterial()
Overrides
UpdateMeshPadding()
Function to be used to force recomputing of character padding when Shader / Material properties have been changed via script.
Declaration
public override void UpdateMeshPadding()
Overrides
UpdateVertexData()
Function to upload the updated vertex data and renderer.
Declaration
public override void UpdateVertexData()
Overrides
UpdateVertexData(TMP_VertexDataUpdateFlags)
Function to upload the updated vertex data and renderer.
Declaration
public override void UpdateVertexData(TMP_VertexDataUpdateFlags flags)
Parameters
Type | Name | Description |
---|---|---|
TMP_VertexDataUpdateFlags | flags |
Overrides
Events
OnPreRenderText
Event to allow users to modify the content of the text info before the text is rendered.
Declaration
public override event Action<TMP_TextInfo> OnPreRenderText
Event Type
Type | Description |
---|---|
Action<TMP_TextInfo> |