3 using System.Collections;
4 using System.Collections.Generic;
11 #pragma warning disable 0414 // Disabled a few warnings related to serialized variables not used in this script but used in the editor. 17 [DisallowMultipleComponent]
18 [RequireComponent(typeof(RectTransform))]
19 [RequireComponent(typeof(CanvasRenderer))]
20 [AddComponentMenu(
"UI/TextMeshPro - Text (UI)", 11)]
28 get {
return TMP_MaterialManager.GetMaterialForRendering(
this, m_sharedMaterial); }
36 get {
return m_autoSizeTextContainer; }
38 set {
if (m_autoSizeTextContainer == value)
return; m_autoSizeTextContainer = value;
if (m_autoSizeTextContainer) { CanvasUpdateRegistry.RegisterCanvasElementForLayoutRebuild(
this);
SetLayoutDirty(); } }
46 public override Mesh
mesh 48 get {
return m_mesh; }
59 if (m_canvasRenderer ==
null) m_canvasRenderer = GetComponent<CanvasRenderer>();
61 return m_canvasRenderer;
88 if (!this.gameObject.activeInHierarchy)
91 if (m_isCalculateSizeRequired || m_rectTransform.hasChanged)
97 m_isLayoutDirty =
true;
110 if (!this.gameObject.activeInHierarchy)
113 if (m_isCalculateSizeRequired || m_rectTransform.hasChanged)
119 m_isLayoutDirty =
true;
122 m_isCalculateSizeRequired =
false;
126 public override void SetVerticesDirty()
128 if (m_verticesAlreadyDirty ||
this ==
null || !this.IsActive() || CanvasUpdateRegistry.IsRebuildingGraphics())
131 m_verticesAlreadyDirty =
true;
132 CanvasUpdateRegistry.RegisterCanvasElementForGraphicRebuild((ICanvasElement)
this);
134 if (m_OnDirtyVertsCallback !=
null)
135 m_OnDirtyVertsCallback();
144 m_isPreferredWidthDirty =
true;
145 m_isPreferredHeightDirty =
true;
147 if ( m_layoutAlreadyDirty ||
this ==
null || !this.IsActive())
150 m_layoutAlreadyDirty =
true;
153 m_isLayoutDirty =
true;
155 if (m_OnDirtyLayoutCallback !=
null)
156 m_OnDirtyLayoutCallback();
167 if (
this ==
null || !this.IsActive() || CanvasUpdateRegistry.IsRebuildingGraphics())
170 m_isMaterialDirty =
true;
171 CanvasUpdateRegistry.RegisterCanvasElementForGraphicRebuild((ICanvasElement)
this);
173 if (m_OnDirtyMaterialCallback !=
null)
174 m_OnDirtyMaterialCallback();
183 m_isInputParsingRequired =
true;
196 public override void Rebuild(CanvasUpdate update)
198 if (
this ==
null)
return;
200 if (update == CanvasUpdate.Prelayout)
202 if (m_autoSizeTextContainer)
207 else if (update == CanvasUpdate.PreRender)
211 m_verticesAlreadyDirty =
false;
212 m_layoutAlreadyDirty =
false;
214 if (!m_isMaterialDirty)
return;
217 m_isMaterialDirty =
false;
227 if (m_textInfo ==
null)
return;
229 for (
int i = 1; i < m_subTextObjects.Length && m_subTextObjects[i] !=
null; i++)
244 Material mat = baseMaterial;
246 if (m_ShouldRecalculateStencil)
248 m_stencilID = TMP_MaterialManager.GetStencilID(gameObject);
249 m_ShouldRecalculateStencil =
false;
258 mat = TMP_MaterialManager.GetStencilMaterial(baseMaterial, m_stencilID);
259 if (m_MaskMaterial !=
null)
260 TMP_MaterialManager.ReleaseStencilMaterial(m_MaskMaterial);
262 m_MaskMaterial = mat;
279 if (m_sharedMaterial ==
null)
return;
281 if (m_canvasRenderer ==
null) m_canvasRenderer = this.
canvasRenderer;
283 m_canvasRenderer.materialCount = 1;
310 get {
return m_maskOffset; }
311 set { m_maskOffset = value; UpdateMask(); m_havePropertiesChanged =
true; }
336 base.RecalculateClipping();
347 this.m_ShouldRecalculateStencil =
true;
356 public override void Cull(Rect clipRect,
bool validRect)
358 if (m_ignoreRectMaskCulling)
return;
360 base.Cull(clipRect, validRect);
426 m_padding = ShaderUtilities.GetPadding(m_sharedMaterial, m_enableExtraPadding, m_isUsingBold);
427 m_isMaskingEnabled = ShaderUtilities.IsMaskingEnabled(m_sharedMaterial);
428 m_havePropertiesChanged =
true;
429 checkPaddingRequired =
false;
432 if (m_textInfo ==
null)
return;
435 for (
int i = 1; i < m_textInfo.materialCount; i++)
449 int materialCount = m_textInfo.materialCount;
451 for (
int i = 1; i < materialCount; i++)
453 m_subTextObjects[i].CrossFadeColor(targetColor, duration, ignoreTimeScale, useAlpha);
466 int materialCount = m_textInfo.materialCount;
468 for (
int i = 1; i < materialCount; i++)
470 m_subTextObjects[i].CrossFadeAlpha(
alpha, duration, ignoreTimeScale);
482 m_havePropertiesChanged =
true;
493 m_havePropertiesChanged =
true;
494 m_ignoreActiveState =
true;
514 if (m_canvas ==
null) m_canvas = this.canvas;
528 m_canvasRenderer.SetMesh(
null);
530 for (
int i = 1; i < m_subTextObjects.Length && m_subTextObjects[i] !=
null; i++)
552 mesh.RecalculateBounds();
556 m_canvasRenderer.SetMesh(
mesh);
570 int materialCount = m_textInfo.materialCount;
572 for (
int i = 0; i < materialCount; i++)
588 mesh.vertices = m_textInfo.meshInfo[i].vertices;
591 mesh.uv = m_textInfo.meshInfo[i].uvs0;
594 mesh.uv2 = m_textInfo.meshInfo[i].uvs2;
600 mesh.colors32 = m_textInfo.meshInfo[i].colors32;
602 mesh.RecalculateBounds();
605 m_canvasRenderer.SetMesh(
mesh);
617 int materialCount = m_textInfo.materialCount;
619 for (
int i = 0; i < materialCount; i++)
634 mesh.vertices = m_textInfo.meshInfo[i].vertices;
635 mesh.uv = m_textInfo.meshInfo[i].uvs0;
636 mesh.uv2 = m_textInfo.meshInfo[i].uvs2;
638 mesh.colors32 = m_textInfo.meshInfo[i].colors32;
640 mesh.RecalculateBounds();
643 m_canvasRenderer.SetMesh(
mesh);
650 public void UpdateFontAsset()
Vector2 GetPreferredValues()
Function to Calculate the Preferred Width and Height of the text object.
override void GenerateTextMesh()
This is the main function that is responsible for creating / displaying the text.
TextRenderFlags
Flags controlling what vertex data gets pushed to the mesh.
override void Cull(Rect clipRect, bool validRect)
Override of the Cull function to provide for the ability to override the culling of the text object.
void ClearUnusedVertices()
Function to clear the vertices while preserving the Triangles, Normals and Tangents.
float alpha
Sets the vertex color alpha value.
override void ForceMeshUpdate()
Function to force regeneration of the mesh before its normal process time. This is useful when change...
Vector4 maskOffset
Sets the masking offset from the bounds of the object
override void SetLayoutDirty()
new CanvasRenderer canvasRenderer
Reference to the CanvasRenderer used by the text object.
Class which contains information about every element contained within the text object.
override void Rebuild(CanvasUpdate update)
override void UpdateVertexData(TMP_VertexDataUpdateFlags flags)
Function to upload the updated vertex data and renderer.
override void SetMaterialDirty()
override Material materialForRendering
Get the material that will be used for rendering.
void CalculateLayoutInputVertical()
Function called by Unity when the vertical layout needs to be recalculated.
override bool autoSizeTextContainer
Determines if the size of the text container will be adjusted to fit the text object when it is first...
void StringToCharArray(string sourceText, ref int[] charBuffer)
Method to store the content of a string into an integer array.
override void RecalculateMasking()
Method called when Stencil Mask needs to be updated on this element and parents.
bool m_isRebuildingLayout
Anchor dampening prevents the anchor position from being adjusted unless the positional change exceed...
Mesh mesh
The Mesh of this text sub object.
Base class which contains common properties and functions shared between the TextMeshPro and TextMesh...
TMP_VertexDataUpdateFlags
Flags to control what vertex data is pushed to the mesh and renderer.
override Mesh mesh
Reference to the Mesh used by the text object.
float GetPreferredHeight()
Method to calculate the preferred height of a text object.
override Material GetModifiedMaterial(Material baseMaterial)
new RectTransform rectTransform
Returns are reference to the RectTransform
override void SetAllDirty()
float GetPreferredWidth()
Method to calculate the preferred width of a text object.
override void LoadFontAsset()
Method which derived classes need to override to load Font Assets.
override void InternalCrossFadeColor(Color targetColor, float duration, bool ignoreTimeScale, bool useAlpha)
Tweens the CanvasRenderer color associated with this Graphic.
override void ClearMesh()
Function to clear the geometry of the Primary and Sub Text objects.
override void UpdateMeshPadding()
Function to be used to force recomputing of character padding when Shader / Material properties have ...
override int SetArraySizes(int[] chars)
Method used to determine the number of visible characters and required buffer allocations.
override void RecalculateClipping()
Method called when the state of a parent changes.
override void UpdateMaterial()
new CanvasRenderer canvasRenderer
The Mesh Renderer of this text sub object.
override void InternalCrossFadeAlpha(float alpha, float duration, bool ignoreTimeScale)
Tweens the alpha of the CanvasRenderer color associated with this Graphic.
override void ComputeMarginSize()
Update the margin width and height
override void UpdateGeometry(Mesh mesh, int index)
Function to force the regeneration of the text object.
override void ForceMeshUpdate(bool ignoreInactive)
Function to force regeneration of the mesh before its normal process time. This is useful when change...
override void UpdateVertexData()
Function to upload the updated vertex data and renderer.
override TMP_TextInfo GetTextInfo(string text)
Function used to evaluate the length of a text string.
string text
A string containing the text to be displayed.
void UpdateSubObjectPivot()
Method to keep the pivot of the sub text objects in sync with the parent pivot.
void CalculateLayoutInputHorizontal()
Function called by Unity when the horizontal layout needs to be recalculated.
TMP_TextInfo textInfo
Returns data about the text object which includes information about each character,...