Class UITextFieldBuilder
Fluent builder for creating and configuring TMP_InputField elements at
runtime. All configuration methods return the same builder instance, enabling
chainable method calls. Call Build() or TryBuild(out TMP_InputField) as
the terminal step to construct the Unity hierarchy and obtain the input field
component.
Inherited Members
Namespace: Scylla.Core.Util.UI
Assembly: ScyllaCore.dll
Syntax
public sealed class UITextFieldBuilder
Remarks
The builder constructs the full TMP_InputField hierarchy including
a root container with an Image background, a text area child with
a RectMask2D for clipping, and separate TMP label objects for the
placeholder and input text. The entire hierarchy is assigned to the UI
layer via UIUtil.AddToUILayerRecursive.
Supports single-line, multi-line, and multi-line-submit modes. The line type is set via SingleLine(), MultiLine(), or MultiLineSubmit().
Example usage:
var field = new UITextFieldBuilder()
.WithParent(contentTransform)
.WithPlaceholder("Enter name...")
.WithSize(300f, 36f)
.WithContentType(TMP_InputField.ContentType.Alphanumeric)
.OnEndEdit(value => Debug.Log($"Submitted: {value}"))
.Build();
Methods
AtPosition(float, float)
Sets the anchored position offset of the input field container.
Declaration
public UITextFieldBuilder AtPosition(float x, float y)
Parameters
| Type | Name | Description |
|---|---|---|
| float | x | Horizontal offset in pixels from the anchor point. |
| float | y | Vertical offset in pixels from the anchor point. |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
See Also
AtPosition(Vector2)
Sets the anchored position offset of the input field container.
Declaration
public UITextFieldBuilder AtPosition(Vector2 position)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | position | Pixel offset from the anchor point applied to the root container's
|
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
See Also
Build()
Builds and returns a fully configured TMP_InputField component.
Declaration
public TMP_InputField Build()
Returns
| Type | Description |
|---|---|
| TMP_InputField | The newly created |
Remarks
Constructs the following hierarchy under the root container:
- Root GameObject -
Image(background),TMP_InputField - Text Area child -
RectMask2Dfor text clipping - Placeholder child inside Text Area - italic
TextMeshProUGUI - Text child inside Text Area - input
TextMeshProUGUI
The entire hierarchy is assigned to the UI layer via
UIUtil.AddToUILayerRecursive. Any registered event callbacks
are connected to the corresponding TMP_InputField events.
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the builder configuration is logically invalid. |
BuildAbstract()
Builds the input field and wraps it in an IUITextField abstraction. Use this overload when consumers should interact with the element through the interface rather than the concrete TMP type.
Declaration
public IUITextField BuildAbstract()
Returns
| Type | Description |
|---|---|
| IUITextField | A UITextFieldComponent wrapping the newly created
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the builder configuration is invalid. See Build(). |
Interactable(bool)
Sets whether the input field responds to user interaction.
Declaration
public UITextFieldBuilder Interactable(bool enabled = true)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | enabled |
|
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
MultiLine()
Configures the input field as a multi-line text area where pressing Enter inserts a newline character.
Declaration
public UITextFieldBuilder MultiLine()
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
See Also
MultiLineSubmit()
Configures the input field as a multi-line text area where pressing Enter triggers the end-edit callback rather than inserting a newline. Use Shift+Enter to insert a newline in this mode.
Declaration
public UITextFieldBuilder MultiLineSubmit()
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
See Also
OnDeselect(UnityAction<string>)
Registers a callback that is invoked when the input field loses focus (is deselected by the user).
Declaration
public UITextFieldBuilder OnDeselect(UnityAction<string> action)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityAction<string> | action | A |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
OnEndEdit(UnityAction<string>)
Registers a callback that is invoked when the user finishes editing the field by pressing Enter (single-line) or by clicking away.
Declaration
public UITextFieldBuilder OnEndEdit(UnityAction<string> action)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityAction<string> | action | A |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
OnSelect(UnityAction<string>)
Registers a callback that is invoked when the input field receives focus (is selected by the user).
Declaration
public UITextFieldBuilder OnSelect(UnityAction<string> action)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityAction<string> | action | A |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
OnValueChanged(UnityAction<string>)
Registers a callback that is invoked every time the input field's text value changes as the user types.
Declaration
public UITextFieldBuilder OnValueChanged(UnityAction<string> action)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityAction<string> | action | A |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
SingleLine()
Configures the input field as a single-line field where pressing Enter submits or deselects.
Declaration
public UITextFieldBuilder SingleLine()
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
See Also
TryBuild(out TMP_InputField)
Attempts to build the TMP_InputField component, suppressing any
exception and reporting failure through the return value instead.
Declaration
public bool TryBuild(out TMP_InputField inputField)
Parameters
| Type | Name | Description |
|---|---|---|
| TMP_InputField | inputField | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
TryBuildAbstract(out IUITextField)
Attempts to build the input field as an IUITextField abstraction, suppressing any exception and reporting failure through the return value instead.
Declaration
public bool TryBuildAbstract(out IUITextField textField)
Parameters
| Type | Name | Description |
|---|---|---|
| IUITextField | textField | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
WithAnchor(UIAlignment)
Sets the anchor and pivot configuration for the root container's
RectTransform by deriving a UIAnchor from the
specified alignment.
Declaration
public UITextFieldBuilder WithAnchor(UIAlignment alignment)
Parameters
| Type | Name | Description |
|---|---|---|
| UIAlignment | alignment | A UIAlignment value representing one of the nine standard anchor positions. Internally resolved via FromAlignment(UIAlignment). |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
See Also
WithAnchor(UIAnchor)
Sets the anchor and pivot configuration for the root container's
RectTransform using an explicit UIAnchor value.
Declaration
public UITextFieldBuilder WithAnchor(UIAnchor anchor)
Parameters
| Type | Name | Description |
|---|---|---|
| UIAnchor | anchor | The UIAnchor describing the |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
See Also
WithBackgroundColor(Color)
Sets the background color of the input field container.
Declaration
public UITextFieldBuilder WithBackgroundColor(Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The RGBA color applied to the root container's |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
WithCharacterLimit(int)
Sets the maximum number of characters the field will accept from user input.
Declaration
public UITextFieldBuilder WithCharacterLimit(int limit)
Parameters
| Type | Name | Description |
|---|---|---|
| int | limit | The maximum character count. A value of |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
WithContentType(ContentType)
Sets the TMP content type, which controls input validation and character filtering on the field.
Declaration
public UITextFieldBuilder WithContentType(TMP_InputField.ContentType contentType)
Parameters
| Type | Name | Description |
|---|---|---|
| TMP_InputField.ContentType | contentType | A |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
WithFont(TMP_FontAsset)
Sets the TMP font asset applied to both the input text and placeholder labels.
Declaration
public UITextFieldBuilder WithFont(TMP_FontAsset font)
Parameters
| Type | Name | Description |
|---|---|---|
| TMP_FontAsset | font | The |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
WithFontSize(float)
Sets the font size in points for both the input text and placeholder labels.
Declaration
public UITextFieldBuilder WithFontSize(float size)
Parameters
| Type | Name | Description |
|---|---|---|
| float | size | The desired font size, clamped to the range [MIN_FONT_SIZE, MAX_FONT_SIZE] (1 to 500 points). |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
WithName(string)
Sets the name of the input field's root GameObject.
Declaration
public UITextFieldBuilder WithName(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name to give the created GameObject. When |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
WithPadding(UIPadding)
Sets the internal padding between the field border and the text area.
Declaration
public UITextFieldBuilder WithPadding(UIPadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| UIPadding | padding | A UIPadding value applied as offset insets on the text
area |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
See Also
WithPadding(float)
Sets the internal padding between the field border and the text area using a uniform value for all four sides.
Declaration
public UITextFieldBuilder WithPadding(float uniform)
Parameters
| Type | Name | Description |
|---|---|---|
| float | uniform | The padding in pixels applied equally to all four sides. Values below
zero are not clamped here; pass |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
See Also
WithParent(Transform)
Sets the parent transform that the input field hierarchy will be attached to.
Declaration
public UITextFieldBuilder WithParent(Transform parent)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | parent | The transform to use as the parent. Pass |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
WithPlaceholder(string)
Sets the placeholder text displayed when the field is empty and not focused.
Declaration
public UITextFieldBuilder WithPlaceholder(string placeholder)
Parameters
| Type | Name | Description |
|---|---|---|
| string | placeholder | The hint string shown in italic style. Pass |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
WithPlaceholderColor(Color)
Sets the color of the placeholder text shown when the field is empty.
Declaration
public UITextFieldBuilder WithPlaceholderColor(Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The RGBA color for the placeholder label. Defaults to semi-transparent grey (0.5, 0.5, 0.5, 0.5). Typically set with a low alpha so it does not compete visually with entered text. |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
WithSize(float, float)
Sets the explicit width and height of the root container's
RectTransform.
Declaration
public UITextFieldBuilder WithSize(float width, float height)
Parameters
| Type | Name | Description |
|---|---|---|
| float | width | Width in pixels. Clamped to a minimum of 10 pixels. |
| float | height | Height in pixels. Clamped to a minimum of 10 pixels. |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
See Also
WithSize(Vector2)
Sets the explicit width and height of the root container's
RectTransform.
Declaration
public UITextFieldBuilder WithSize(Vector2 size)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | size | A |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
See Also
WithText(string)
Sets the initial text that pre-populates the input field when it is created.
Declaration
public UITextFieldBuilder WithText(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The string to place in the field. Pass |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |
WithTextColor(Color)
Sets the color of the input text label inside the field.
Declaration
public UITextFieldBuilder WithTextColor(Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The RGBA color applied to the input text. Defaults to |
Returns
| Type | Description |
|---|---|
| UITextFieldBuilder | This builder instance, enabling fluent method chaining. |