Class UITextFieldComponent
Concrete implementation of IUITextField that wraps a
TMP_InputField and provides a TMP-agnostic interface for input field operations.
Inherited Members
Namespace: Scylla.Core.Util.UI
Assembly: ScyllaCore.dll
Syntax
public sealed class UITextFieldComponent : IUITextField, IDisposable
Remarks
UITextFieldComponent is a plain C# class - it is NOT a MonoBehaviour and does
not participate in the Unity component lifecycle.
The constructor throws ArgumentNullException when the supplied
inputField argument is null. TMP event listeners are subscribed during
construction and unsubscribed in Dispose().
Double-dispose is safe. Calling Dispose() a second time is a no-op because
an internal _isDisposed guard prevents redundant unsubscription.
Constructors
UITextFieldComponent(TMP_InputField)
Creates a new UITextFieldComponent wrapping the given TMP_InputField
and subscribes to its value-changed and submit events.
Declaration
public UITextFieldComponent(TMP_InputField inputField)
Parameters
| Type | Name | Description |
|---|---|---|
| TMP_InputField | inputField | The |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
Properties
CaretPosition
Gets or sets the zero-based index of the text cursor position within Text.
Declaration
public int CaretPosition { get; set; }
Property Value
| Type | Description |
|---|---|
| int | A value between |
GameObject
Gets the UnityEngine.GameObject that hosts this input field component.
Declaration
public GameObject GameObject { get; }
Property Value
| Type | Description |
|---|---|
| GameObject | The root GameObject of the input field widget. |
Interactable
Gets or sets whether the input field responds to user interaction.
Declaration
public bool Interactable { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
|
IsFocused
Gets whether the input field currently has keyboard focus.
Declaration
public bool IsFocused { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
RectTransform
Gets the RectTransform of the input field root, used for anchoring, sizing, and layout group placement.
Declaration
public RectTransform RectTransform { get; }
Property Value
| Type | Description |
|---|---|
| RectTransform | The |
Text
Gets or sets the current text content of the input field.
Declaration
public string Text { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The raw string value typed by the user. Setting this value replaces the entire content and fires OnValueChanged if the new value differs from the previous one. |
Methods
Clear()
Clears all text content, setting Text to an empty string.
Declaration
public void Clear()
Remarks
Implementations should fire OnValueChanged with an empty string when the previous content was non-empty.
Dispose()
Declaration
public void Dispose()
Focus()
Activates the input field and gives it keyboard focus, placing the cursor at the end of the current text.
Declaration
public void Focus()
SetCaretColor(Color)
Sets the color of the blinking text cursor (caret).
Declaration
public void SetCaretColor(Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The UnityEngine.Color to apply to the caret graphic. |
SetCharacterFilter(Func<char, bool>)
Installs a per-character filter that controls which characters may be appended to the field's text.
Declaration
public void SetCharacterFilter(Func<char, bool> filter)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<char, bool> | filter | A predicate that receives each candidate character and returns |
Remarks
The filter is evaluated before OnValueChanged fires. Characters rejected by the filter are silently discarded and do not appear in the field.
A common use case is restricting input to digits-only:
inputField.SetCharacterFilter(c => char.IsDigit(c));
SetFont(UIFontReference)
Replaces the current font asset used by the input field.
Declaration
public void SetFont(UIFontReference fontReference)
Parameters
| Type | Name | Description |
|---|---|---|
| UIFontReference | fontReference | A UIFontReference that wraps the desired |
SetFontSize(float)
Sets the font size of the input text in points.
Declaration
public void SetFontSize(float size)
Parameters
| Type | Name | Description |
|---|---|---|
| float | size | The desired font size. Should be a positive value within the range MIN_FONT_SIZE to MAX_FONT_SIZE. |
SetPlaceholderColor(Color)
Sets the color of the placeholder text that appears when the field is empty.
Declaration
public void SetPlaceholderColor(Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The UnityEngine.Color for the placeholder. Typically a semi-transparent version of the text color to visually distinguish it from real input. |
SetTextColor(Color)
Sets the color of the input text.
Declaration
public void SetTextColor(Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The UnityEngine.Color to apply to the typed text. The alpha component controls transparency. |
Unfocus()
Removes keyboard focus from the input field without clearing its content.
Declaration
public void Unfocus()
Events
OnSubmit
Raised when the user confirms their input by pressing Enter (or the platform submit key), providing the final text value.
Declaration
public event Action<string> OnSubmit
Event Type
| Type | Description |
|---|---|
| Action<string> |
Remarks
The string argument is equivalent to Text at the moment of submission. The field is not automatically cleared or unfocused on submit; call Clear() or Unfocus() explicitly if needed.
OnValueChanged
Raised each time the text content changes, either from user typing or a programmatic assignment to Text.
Declaration
public event Action<string> OnValueChanged
Event Type
| Type | Description |
|---|---|
| Action<string> |
Remarks
The string argument contains the complete current value of the field after the change, not just the delta.