Class UITextComponent
Concrete implementation of IUIText that wraps a TextMeshProUGUI
component and provides zero-allocation pass-through for high-performance text operations.
Implements
Inherited Members
Namespace: Scylla.Core.Util.UI
Assembly: ScyllaCore.dll
Syntax
public sealed class UITextComponent : IUIText
Remarks
UITextComponent is a lightweight plain C# class - it is NOT a MonoBehaviour and
does not participate in the Unity component lifecycle.
When the wrapped TextMeshProUGUI reference is null, all property getters
return safe defaults (null, string.Empty, 0f, false) and all
methods are silent no-ops. Use IsValid to check whether the wrapped
reference is present before relying on any returned value.
For hot-path, zero-allocation text updates prefer SetCharArray(char[], int, int) over
SetText(string). SetCharArray writes directly into the TMP internal buffer
without producing a managed string allocation.
Constructors
UITextComponent(TextMeshProUGUI)
Creates a new UITextComponent wrapping the specified TMP text component.
Declaration
public UITextComponent(TextMeshProUGUI tmpText)
Parameters
| Type | Name | Description |
|---|---|---|
| TextMeshProUGUI | tmpText | The |
Properties
FontSize
Gets the current rendered font size in points.
Declaration
public float FontSize { get; }
Property Value
| Type | Description |
|---|---|
| float | The font size applied to the underlying |
GameObject
Gets the UnityEngine.GameObject that hosts this text component.
Declaration
public GameObject GameObject { get; }
Property Value
| Type | Description |
|---|---|
| GameObject | The root GameObject of the text element. |
IsValid
Gets whether this text component is valid and safe to use.
Declaration
public bool IsValid { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
RectTransform
Gets the RectTransform of the text element, used for anchoring, sizing, and placement within a layout.
Declaration
public RectTransform RectTransform { get; }
Property Value
| Type | Description |
|---|---|
| RectTransform | The |
Text
Gets or sets the displayed text string.
Declaration
public string Text { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The current text content. Setting this property allocates a managed string and triggers a TMP mesh rebuild. For frequent per-frame updates prefer SetCharArray(char[], int, int) to avoid allocations. |
Methods
SetAlignment(UIAlignment)
Sets the horizontal and vertical text alignment within the element's bounds.
Declaration
public void SetAlignment(UIAlignment alignment)
Parameters
| Type | Name | Description |
|---|---|---|
| UIAlignment | alignment | The UIAlignment position to apply. The mapping to TMP's
|
SetCharArray(char[], int, int)
Updates the displayed text from a subsection of a character array without allocating a managed string.
Declaration
public void SetCharArray(char[] chars, int start, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| char[] | chars | The source character array. Must not be |
| int | start | The zero-based index of the first character to copy from |
| int | length | The number of characters to copy starting at |
Remarks
This is the preferred method for high-frequency text updates such as timers, score counters, or live debug readouts because it avoids a heap allocation on every call.
SetColor(Color)
Sets the vertex color of all characters in this text element.
Declaration
public void SetColor(Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The UnityEngine.Color to apply. Rich text color tags embedded in the text string will override this base color for their respective spans when rich text is enabled. |
SetFont(UIFontReference)
Replaces the font asset used for rendering this text element.
Declaration
public void SetFont(UIFontReference fontReference)
Parameters
| Type | Name | Description |
|---|---|---|
| UIFontReference | fontReference | A UIFontReference wrapping the desired |
SetFontSize(float)
Sets the font size in points.
Declaration
public void SetFontSize(float size)
Parameters
| Type | Name | Description |
|---|---|---|
| float | size | The desired font size. Should fall within MIN_FONT_SIZE to MAX_FONT_SIZE. Values outside this range are accepted by TMP but may produce unusable results. |
SetFontStyle(UIFontStyle)
Applies a combination of font style flags to the text element.
Declaration
public void SetFontStyle(UIFontStyle style)
Parameters
| Type | Name | Description |
|---|---|---|
| UIFontStyle | style | A UIFontStyle flags value. Multiple styles can be combined with
the bitwise OR operator, for example
|
SetRichText(bool)
Enables or disables TMP rich text tag parsing for this element.
Declaration
public void SetRichText(bool enabled)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | enabled |
|
SetText(string)
Replaces the displayed text with the given string.
Declaration
public void SetText(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The new text to display. Passing |
SetWordWrap(bool)
Enables or disables automatic line-breaking at word boundaries when the text exceeds the element's width.
Declaration
public void SetWordWrap(bool enabled)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | enabled |
|