Editable text input field.
Inheritance
TMP_InputField
Inherited Members
UnityEngine.UI.Selectable.OnValidate()
UnityEngine.UI.Selectable.Reset()
UnityEngine.UI.Selectable.animator
Namespace: TMPro
[AddComponentMenu("UI/TextMeshPro - Input Field", 11)]
[HelpURL("https://docs.unity3d.com/Packages/com.unity.textmeshpro@3.2")]
public class TMP_InputField : Selectable, IMoveHandler, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, IUpdateSelectedHandler, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerClickHandler, ISubmitHandler, ICanvasElement, ILayoutElement, IScrollHandler, IEventSystemHandler
Constructors
Declaration
protected TMP_InputField()
Fields
Determines if the keyboard is opened in alert mode.
Declaration
Field Value
Declaration
protected int m_CaretPosition
Field Value
Declaration
protected int m_CaretSelectPosition
Field Value
Declaration
protected bool m_CaretVisible
Field Value
Declaration
protected UIVertex[] m_CursorVerts
Field Value
Declaration
[SerializeField]
protected FontAsset m_GlobalFontAsset
Field Value
Type |
Description |
UnityEngine.TextCore.Text.FontAsset |
|
Declaration
[SerializeField]
protected TMP_InputValidator m_InputValidator
Field Value
m_isRichTextEditingAllowed
Declaration
[SerializeField]
protected bool m_isRichTextEditingAllowed
Field Value
Declaration
protected bool m_isSelectAll
Field Value
Declaration
[SerializeField]
protected int m_LineLimit
Field Value
Declaration
[NonSerialized]
protected Mesh m_Mesh
Field Value
Declaration
[SerializeField]
protected bool m_OnFocusSelectAll
Field Value
Declaration
[SerializeField]
protected Graphic m_Placeholder
Field Value
Text Text used to display the input's value.
Declaration
protected RectTransform m_RectTransform
Field Value
Declaration
[SerializeField]
protected bool m_ResetOnDeActivation
Field Value
Declaration
[SerializeField]
protected float m_ScrollSensitivity
Field Value
Declaration
protected TouchScreenKeyboard m_SoftKeyboard
Field Value
Declaration
protected int m_StringPosition
Field Value
Declaration
protected int m_StringSelectPosition
Field Value
m_Text
Declaration
[SerializeField]
[TextArea(5, 10)]
protected string m_Text
Field Value
m_TextComponent
Declaration
[SerializeField]
protected TMP_Text m_TextComponent
Field Value
m_TextComponentRectMask
Declaration
protected RectMask2D m_TextComponentRectMask
Field Value
m_TextComponentRectTransform
Declaration
protected RectTransform m_TextComponentRectTransform
Field Value
m_TextViewport
Declaration
[SerializeField]
protected RectTransform m_TextViewport
Field Value
m_TextViewportRectMask
Declaration
protected RectMask2D m_TextViewportRectMask
Field Value
Declaration
[SerializeField]
protected Scrollbar m_VerticalScrollbar
Field Value
Declaration
[SerializeField]
protected TMP_ScrollbarEventHandler m_VerticalScrollbarEventHandler
Field Value
Properties
Declaration
public char asteriskChar { get; set; }
Property Value
Declaration
public float caretBlinkRate { get; set; }
Property Value
Declaration
public Color caretColor { get; set; }
Property Value
Get: Returns the focus position as thats the position that moves around even during selection.
Set: Set both the anchor and focus position such that a selection doesn't happen
Declaration
public int caretPosition { get; set; }
Property Value
Current position of the cursor.
Getters are public Setters are protected
Declaration
protected int caretPositionInternal { get; set; }
Property Value
Declaration
protected int caretSelectPositionInternal { get; set; }
Property Value
Declaration
public int caretWidth { get; set; }
Property Value
Declaration
public int characterLimit { get; set; }
Property Value
The type of validation to perform on a character
Declaration
public TMP_InputField.CharacterValidation characterValidation { get; set; }
Property Value
contentType
Declaration
public TMP_InputField.ContentType contentType { get; set; }
Property Value
Declaration
public bool customCaretColor { get; set; }
Property Value
See ILayoutElement.flexibleHeight.
Declaration
public virtual float flexibleHeight { get; }
Property Value
Implements
See ILayoutElement.flexibleWidth.
Declaration
public virtual float flexibleWidth { get; }
Property Value
Implements
Sets the Font Asset on both Placeholder and Input child objects.
Declaration
public FontAsset fontAsset { get; set; }
Property Value
Type |
Description |
UnityEngine.TextCore.Text.FontAsset |
|
The type of input expected. See InputField.InputType.
Declaration
public TMP_InputField.InputType inputType { get; set; }
Property Value
Sets the Input Validation to use a Custom Input Validation script.
Declaration
public TMP_InputValidator inputValidator { get; set; }
Property Value
Declaration
public bool isFocused { get; }
Property Value
isRichTextEditingAllowed
Is Rich Text editing allowed?
Declaration
public bool isRichTextEditingAllowed { get; set; }
Property Value
keepTextSelectionVisible
Determines if the text selection will remain visible when the input field looses focus and is deactivated.
Declaration
public bool keepTextSelectionVisible { get; set; }
Property Value
They type of mobile keyboard that will be used.
Declaration
public TouchScreenKeyboardType keyboardType { get; set; }
Property Value
See ILayoutElement.layoutPriority.
Declaration
public virtual int layoutPriority { get; }
Property Value
Implements
Limits the number of lines of text in the Input Field.
Declaration
public int lineLimit { get; set; }
Property Value
Declaration
public TMP_InputField.LineType lineType { get; set; }
Property Value
Declaration
protected Mesh mesh { get; }
Property Value
See ILayoutElement.minHeight.
Declaration
public virtual float minHeight { get; }
Property Value
Implements
See ILayoutElement.minWidth.
Declaration
public virtual float minWidth { get; }
Property Value
Implements
Declaration
public bool multiLine { get; }
Property Value
Declaration
public TMP_InputField.SelectionEvent onDeselect { get; set; }
Property Value
Declaration
public TMP_InputField.SubmitEvent onEndEdit { get; set; }
Property Value
onEndTextSelection
Declaration
public TMP_InputField.TextSelectionEvent onEndTextSelection { get; set; }
Property Value
Determines if the whole text will be selected when focused.
Declaration
public bool onFocusSelectAll { get; set; }
Property Value
Declaration
public TMP_InputField.SelectionEvent onSelect { get; set; }
Property Value
Declaration
public TMP_InputField.SubmitEvent onSubmit { get; set; }
Property Value
onTextSelection
Declaration
public TMP_InputField.TextSelectionEvent onTextSelection { get; set; }
Property Value
Declaration
public TMP_InputField.TouchScreenKeyboardEvent onTouchScreenKeyboardStatusChanged { get; set; }
Property Value
Declaration
public TMP_InputField.OnValidateInput onValidateInput { get; set; }
Property Value
Declaration
public TMP_InputField.OnChangeEvent onValueChanged { get; set; }
Property Value
Declaration
public Graphic placeholder { get; set; }
Property Value
Set the point size on both Placeholder and Input text object.
Declaration
public float pointSize { get; set; }
Property Value
Get the height of all the text if constrained to the height of the RectTransform.
Declaration
public virtual float preferredHeight { get; }
Property Value
Implements
Get the displayed with of all input characters.
Declaration
public virtual float preferredWidth { get; }
Property Value
Implements
Declaration
public bool readOnly { get; set; }
Property Value
Determines if the text and caret position as well as selection will be reset when the input field is deactivated.
Declaration
public bool resetOnDeActivation { get; set; }
Property Value
restoreOriginalTextOnEscape
Controls whether the original text is restored when pressing "ESC".
Declaration
public bool restoreOriginalTextOnEscape { get; set; }
Property Value
richText
Declaration
public bool richText { get; set; }
Property Value
Declaration
public float scrollSensitivity { get; set; }
Property Value
Get: Returns the fixed position of selection
Set: If compositionString is 0 set the fixed position
Declaration
public int selectionAnchorPosition { get; set; }
Property Value
Declaration
public Color selectionColor { get; set; }
Property Value
Get: Returns the variable position of selection
Set: If compositionString is 0 set the variable position
Declaration
public int selectionFocusPosition { get; set; }
Property Value
The fixed position of the selection in the raw string which may contains rich text.
Declaration
public int selectionStringAnchorPosition { get; set; }
Property Value
The variable position of the selection in the raw string which may contains rich text.
Declaration
public int selectionStringFocusPosition { get; set; }
Property Value
Should the inputfield be automatically activated upon selection.
Declaration
public virtual bool shouldActivateOnSelect { get; set; }
Property Value
Should the mobile keyboard input be hidden.
Declaration
public bool shouldHideMobileInput { get; set; }
Property Value
Declaration
public bool shouldHideSoftKeyboard { get; set; }
Property Value
Declaration
public int stringPosition { get; set; }
Property Value
Declaration
protected int stringPositionInternal { get; set; }
Property Value
Declaration
protected int stringSelectPositionInternal { get; set; }
Property Value
text
Input field's current text value. This is not necessarily the same as what is visible on screen.
Declaration
public string text { get; set; }
Property Value
Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.
public class Example : MonoBehaviour
{
public InputField mainInputField;
public void Start()
{
mainInputField.text = "Enter Text Here...";
}
}
textComponent
Declaration
public TMP_Text textComponent { get; set; }
Property Value
textViewport
Declaration
public RectTransform textViewport { get; set; }
Property Value
The TouchScreenKeyboard being used to edit the Input Field.
Declaration
public TouchScreenKeyboard touchScreenKeyboard { get; }
Property Value
Declaration
public Scrollbar verticalScrollbar { get; set; }
Property Value
Declaration
public bool wasCanceled { get; }
Property Value
Methods
Declaration
public void ActivateInputField()
Declaration
protected virtual void Append(char input)
Parameters
Type |
Name |
Description |
Char |
input |
|
Append the specified text to the end of the current.
Declaration
protected virtual void Append(string input)
Parameters
Type |
Name |
Description |
String |
input |
|
See ILayoutElement.CalculateLayoutInputHorizontal.
Declaration
public virtual void CalculateLayoutInputHorizontal()
Implements
See ILayoutElement.CalculateLayoutInputVertical.
Declaration
public virtual void CalculateLayoutInputVertical()
Implements
Declaration
protected void ClampCaretPos(ref int pos)
Parameters
Type |
Name |
Description |
Int32 |
pos |
|
Declaration
protected void ClampStringPos(ref int pos)
Parameters
Type |
Name |
Description |
Int32 |
pos |
|
Declaration
public void DeactivateInputField(bool clearSelection = false)
Parameters
Type |
Name |
Description |
Boolean |
clearSelection |
|
Declaration
protected override void DoStateTransition(Selectable.SelectionState state, bool instant)
Parameters
Overrides
Declaration
public void ForceLabelUpdate()
Declaration
public virtual void GraphicUpdateComplete()
Implements
Declaration
protected virtual bool IsValidChar(char c)
Parameters
Type |
Name |
Description |
Char |
c |
|
Returns
Declaration
protected TMP_InputField.EditState KeyPressed(Event evt)
Parameters
Type |
Name |
Description |
Event |
evt |
|
Returns
Update the text based on input.
Declaration
protected virtual void LateUpdate()
Declaration
public virtual void LayoutComplete()
Implements
MoveTextEnd(Boolean)
Move to the end of the text.
Declaration
public void MoveTextEnd(bool shift)
Parameters
Type |
Name |
Description |
Boolean |
shift |
|
MoveTextStart(Boolean)
Move to the start of the text.
Declaration
public void MoveTextStart(bool shift)
Parameters
Type |
Name |
Description |
Boolean |
shift |
|
Move to the end of the current line of text.
Declaration
public void MoveToEndOfLine(bool shift, bool ctrl)
Parameters
Move to the start of the current line of text.
Declaration
public void MoveToStartOfLine(bool shift, bool ctrl)
Parameters
Declaration
public virtual void OnBeginDrag(PointerEventData eventData)
Parameters
Implements
Declaration
public void OnControlClick()
Declaration
public override void OnDeselect(BaseEventData eventData)
Parameters
Overrides
Declaration
protected override void OnDisable()
Overrides
Declaration
public virtual void OnDrag(PointerEventData eventData)
Parameters
Implements
Declaration
protected override void OnEnable()
Overrides
Declaration
public virtual void OnEndDrag(PointerEventData eventData)
Parameters
Implements
Declaration
Declaration
public virtual void OnPointerClick(PointerEventData eventData)
Parameters
Implements
Declaration
public override void OnPointerDown(PointerEventData eventData)
Parameters
Overrides
Declaration
public virtual void OnScroll(PointerEventData eventData)
Parameters
Implements
Declaration
public override void OnSelect(BaseEventData eventData)
Parameters
Overrides
Declaration
public virtual void OnSubmit(BaseEventData eventData)
Parameters
Implements
Declaration
public virtual void OnUpdateSelected(BaseEventData eventData)
Parameters
Implements
Declaration
public void ProcessEvent(Event e)
Parameters
Type |
Name |
Description |
Event |
e |
|
Declaration
public virtual void Rebuild(CanvasUpdate update)
Parameters
Implements
Declaration
public void ReleaseSelection()
Declaration
protected void SelectAll()
Submit the input field's text.
Declaration
protected void SendOnEndEdit()
SendOnEndTextSelection()
Declaration
protected void SendOnEndTextSelection()
Declaration
protected void SendOnFocus()
Declaration
protected void SendOnFocusLost()
Declaration
protected void SendOnSubmit()
SendOnTextSelection()
Declaration
protected void SendOnTextSelection()
Declaration
protected void SendTouchScreenKeyboardStatusChanged()
SetGlobalFontAsset(FontAsset)
Function to conveniently set the Font Asset of both Placeholder and Input Field text object.
Declaration
public void SetGlobalFontAsset(FontAsset fontAsset)
Parameters
Type |
Name |
Description |
UnityEngine.TextCore.Text.FontAsset |
fontAsset |
|
Function to conveniently set the point size of both Placeholder and Input Field text object.
Declaration
public void SetGlobalPointSize(float pointSize)
Parameters
Type |
Name |
Description |
Single |
pointSize |
|
SetTextWithoutNotify(String)
Set Input field's current text value without invoke onValueChanged. This is not necessarily the same as what is visible on screen.
Declaration
public void SetTextWithoutNotify(string input)
Parameters
Type |
Name |
Description |
String |
input |
|
Update the visual text Text.
Declaration
protected void UpdateLabel()
Validate the specified input.
Declaration
protected char Validate(string text, int pos, char ch)
Parameters
Returns