Editable text input field.
Inheritance
System.Object
UnityEngine.EventSystems.UIBehaviour
UnityEngine.UI.Selectable
TMP_InputField
Inherited Members
UnityEngine.UI.Selectable.s_Selectables
UnityEngine.UI.Selectable.s_SelectableCount
UnityEngine.UI.Selectable.m_CurrentIndex
UnityEngine.UI.Selectable.AllSelectablesNoAlloc(UnityEngine.UI.Selectable[])
UnityEngine.UI.Selectable.Awake()
UnityEngine.UI.Selectable.OnCanvasGroupChanged()
UnityEngine.UI.Selectable.IsInteractable()
UnityEngine.UI.Selectable.OnDidApplyAnimationProperties()
UnityEngine.UI.Selectable.OnTransformParentChanged()
UnityEngine.UI.Selectable.OnValidate()
UnityEngine.UI.Selectable.Reset()
UnityEngine.UI.Selectable.InstantClearState()
UnityEngine.UI.Selectable.FindSelectable(UnityEngine.Vector3)
UnityEngine.UI.Selectable.FindSelectableOnLeft()
UnityEngine.UI.Selectable.FindSelectableOnRight()
UnityEngine.UI.Selectable.FindSelectableOnUp()
UnityEngine.UI.Selectable.FindSelectableOnDown()
UnityEngine.UI.Selectable.OnMove(UnityEngine.EventSystems.AxisEventData)
UnityEngine.UI.Selectable.IsHighlighted()
UnityEngine.UI.Selectable.IsPressed()
UnityEngine.UI.Selectable.OnPointerUp(UnityEngine.EventSystems.PointerEventData)
UnityEngine.UI.Selectable.OnPointerEnter(UnityEngine.EventSystems.PointerEventData)
UnityEngine.UI.Selectable.OnPointerExit(UnityEngine.EventSystems.PointerEventData)
UnityEngine.UI.Selectable.Select()
UnityEngine.UI.Selectable.allSelectablesArray
UnityEngine.UI.Selectable.allSelectableCount
UnityEngine.UI.Selectable.allSelectables
UnityEngine.UI.Selectable.navigation
UnityEngine.UI.Selectable.transition
UnityEngine.UI.Selectable.colors
UnityEngine.UI.Selectable.spriteState
UnityEngine.UI.Selectable.animationTriggers
UnityEngine.UI.Selectable.targetGraphic
UnityEngine.UI.Selectable.interactable
UnityEngine.UI.Selectable.image
UnityEngine.UI.Selectable.animator
UnityEngine.UI.Selectable.currentSelectionState
UnityEngine.EventSystems.UIBehaviour.Start()
UnityEngine.EventSystems.UIBehaviour.OnDestroy()
UnityEngine.EventSystems.UIBehaviour.IsActive()
UnityEngine.EventSystems.UIBehaviour.OnRectTransformDimensionsChange()
UnityEngine.EventSystems.UIBehaviour.OnBeforeTransformParentChanged()
UnityEngine.EventSystems.UIBehaviour.OnCanvasHierarchyChanged()
UnityEngine.EventSystems.UIBehaviour.IsDestroyed()
Namespace: TMPro
[AddComponentMenu("UI/TextMeshPro - Input Field", 11)]
public class TMP_InputField : Selectable, IMoveHandler, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, IUpdateSelectedHandler, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerClickHandler, ISubmitHandler, ICanvasElement, IScrollHandler, IEventSystemHandler
Constructors
Declaration
protected TMP_InputField()
Fields
Declaration
protected int m_CaretPosition
Field Value
| Type |
Description |
| System.Int32 |
|
Declaration
protected int m_CaretSelectPosition
Field Value
| Type |
Description |
| System.Int32 |
|
Declaration
protected bool m_CaretVisible
Field Value
| Type |
Description |
| System.Boolean |
|
Declaration
protected UIVertex[] m_CursorVerts
Field Value
Declaration
[SerializeField]
protected TMP_FontAsset m_GlobalFontAsset
Field Value
Declaration
[SerializeField]
protected TMP_InputValidator m_InputValidator
Field Value
m_isRichTextEditingAllowed
Declaration
[SerializeField]
protected bool m_isRichTextEditingAllowed
Field Value
| Type |
Description |
| System.Boolean |
|
Declaration
protected bool m_isSelectAll
Field Value
| Type |
Description |
| System.Boolean |
|
Declaration
protected TouchScreenKeyboard m_Keyboard
Field Value
Declaration
[NonSerialized]
protected Mesh m_Mesh
Field Value
Declaration
[SerializeField]
protected bool m_OnFocusSelectAll
Field Value
| Type |
Description |
| System.Boolean |
|
Declaration
[SerializeField]
protected Graphic m_Placeholder
Field Value
| Type |
Description |
| UnityEngine.UI.Graphic |
|
Declaration
[SerializeField]
protected bool m_ResetOnDeActivation
Field Value
| Type |
Description |
| System.Boolean |
|
Declaration
[SerializeField]
protected float m_ScrollSensitivity
Field Value
| Type |
Description |
| System.Single |
|
Declaration
protected int m_StringPosition
Field Value
| Type |
Description |
| System.Int32 |
|
Declaration
protected int m_StringSelectPosition
Field Value
| Type |
Description |
| System.Int32 |
|
m_Text
Declaration
[SerializeField]
[TextArea(3, 10)]
protected string m_Text
Field Value
| Type |
Description |
| System.String |
|
m_TextComponent
Declaration
[SerializeField]
protected TMP_Text m_TextComponent
Field Value
m_TextComponentRectTransform
Declaration
protected RectTransform m_TextComponentRectTransform
Field Value
m_TextViewport
Text Text used to display the input's value.
Declaration
[SerializeField]
protected RectTransform m_TextViewport
Field Value
Declaration
[SerializeField]
protected Scrollbar m_VerticalScrollbar
Field Value
| Type |
Description |
| UnityEngine.UI.Scrollbar |
|
Declaration
[SerializeField]
protected TMP_ScrollbarEventHandler m_VerticalScrollbarEventHandler
Field Value
Properties
Declaration
public char asteriskChar { get; set; }
Property Value
| Type |
Description |
| System.Char |
|
Declaration
public float caretBlinkRate { get; set; }
Property Value
| Type |
Description |
| System.Single |
|
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
| Type |
Description |
| System.Int32 |
|
Current position of the cursor.
Getters are public Setters are protected
Declaration
protected int caretPositionInternal { get; set; }
Property Value
| Type |
Description |
| System.Int32 |
|
Declaration
protected int caretSelectPositionInternal { get; set; }
Property Value
| Type |
Description |
| System.Int32 |
|
Declaration
public int caretWidth { get; set; }
Property Value
| Type |
Description |
| System.Int32 |
|
Declaration
public int characterLimit { get; set; }
Property Value
| Type |
Description |
| System.Int32 |
|
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
| Type |
Description |
| System.Boolean |
|
Sets the Font Asset on both Placeholder and Input child objects.
Declaration
public TMP_FontAsset fontAsset { get; set; }
Property Value
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
| Type |
Description |
| System.Boolean |
|
isRichTextEditingAllowed
Is Rich Text editing allowed?
Declaration
public bool isRichTextEditingAllowed { get; set; }
Property Value
| Type |
Description |
| System.Boolean |
|
Declaration
public TouchScreenKeyboardType keyboardType { get; set; }
Property Value
Declaration
public TMP_InputField.LineType lineType { get; set; }
Property Value
Declaration
protected Mesh mesh { get; }
Property Value
Declaration
public bool multiLine { get; }
Property Value
| Type |
Description |
| System.Boolean |
|
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
| Type |
Description |
| System.Boolean |
|
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.OnValidateInput onValidateInput { get; set; }
Property Value
Declaration
public TMP_InputField.OnChangeEvent onValueChanged { get; set; }
Property Value
Declaration
public Graphic placeholder { get; set; }
Property Value
| Type |
Description |
| UnityEngine.UI.Graphic |
|
Set the point size on both Placeholder and Input text object.
Declaration
public float pointSize { get; set; }
Property Value
| Type |
Description |
| System.Single |
|
Declaration
public bool readOnly { get; set; }
Property Value
| Type |
Description |
| System.Boolean |
|
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
| Type |
Description |
| System.Boolean |
|
restoreOriginalTextOnEscape
Controls whether the original text is restored when pressing "ESC".
Declaration
public bool restoreOriginalTextOnEscape { get; set; }
Property Value
| Type |
Description |
| System.Boolean |
|
richText
Declaration
public bool richText { get; set; }
Property Value
| Type |
Description |
| System.Boolean |
|
Declaration
public float scrollSensitivity { get; set; }
Property Value
| Type |
Description |
| System.Single |
|
Get: Returns the fixed position of selection
Set: If Input.compositionString is 0 set the fixed position
Declaration
public int selectionAnchorPosition { get; set; }
Property Value
| Type |
Description |
| System.Int32 |
|
Declaration
public Color selectionColor { get; set; }
Property Value
Get: Returns the variable position of selection
Set: If Input.compositionString is 0 set the variable position
Declaration
public int selectionFocusPosition { get; set; }
Property Value
| Type |
Description |
| System.Int32 |
|
The fixed position of the selection in the raw string which may contains rich text.
Declaration
public int selectionStringAnchorPosition { get; set; }
Property Value
| Type |
Description |
| System.Int32 |
|
The variable position of the selection in the raw string which may contains rich text.
Declaration
public int selectionStringFocusPosition { get; set; }
Property Value
| Type |
Description |
| System.Int32 |
|
Should the mobile keyboard input be hidden.
Declaration
public bool shouldHideMobileInput { get; set; }
Property Value
| Type |
Description |
| System.Boolean |
|
Declaration
public int stringPosition { get; set; }
Property Value
| Type |
Description |
| System.Int32 |
|
Declaration
protected int stringPositionInternal { get; set; }
Property Value
| Type |
Description |
| System.Int32 |
|
Declaration
protected int stringSelectPositionInternal { get; set; }
Property Value
| Type |
Description |
| System.Int32 |
|
text
Input field's current text value.
Declaration
public string text { get; set; }
Property Value
| Type |
Description |
| System.String |
|
textComponent
Declaration
public TMP_Text textComponent { get; set; }
Property Value
textViewport
Declaration
public RectTransform textViewport { get; set; }
Property Value
Declaration
public Scrollbar verticalScrollbar { get; set; }
Property Value
| Type |
Description |
| UnityEngine.UI.Scrollbar |
|
Declaration
public bool wasCanceled { get; }
Property Value
| Type |
Description |
| System.Boolean |
|
Methods
Declaration
public void ActivateInputField()
Declaration
protected virtual void Append(char input)
Parameters
| Type |
Name |
Description |
| System.Char |
input |
|
Append the specified text to the end of the current.
Declaration
protected virtual void Append(string input)
Parameters
| Type |
Name |
Description |
| System.String |
input |
|
Declaration
protected void ClampCaretPos(ref int pos)
Parameters
| Type |
Name |
Description |
| System.Int32 |
pos |
|
Declaration
protected void ClampStringPos(ref int pos)
Parameters
| Type |
Name |
Description |
| System.Int32 |
pos |
|
Declaration
public void DeactivateInputField()
Declaration
protected override void DoStateTransition(Selectable.SelectionState state, bool instant)
Parameters
| Type |
Name |
Description |
| UnityEngine.UI.Selectable.SelectionState |
state |
|
| System.Boolean |
instant |
|
Overrides
UnityEngine.UI.Selectable.DoStateTransition(UnityEngine.UI.Selectable.SelectionState, System.Boolean)
Declaration
public void ForceLabelUpdate()
Declaration
public virtual void GraphicUpdateComplete()
Implements
UnityEngine.UI.ICanvasElement.GraphicUpdateComplete()
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
UnityEngine.UI.ICanvasElement.LayoutComplete()
MoveTextEnd(Boolean)
Move to the end of the text.
Declaration
public void MoveTextEnd(bool shift)
Parameters
| Type |
Name |
Description |
| System.Boolean |
shift |
|
MoveTextStart(Boolean)
Move to the start of the text.
Declaration
public void MoveTextStart(bool shift)
Parameters
| Type |
Name |
Description |
| System.Boolean |
shift |
|
Move to the end of the current line of text.
Declaration
public void MoveToEndOfLine(bool shift, bool ctrl)
Parameters
| Type |
Name |
Description |
| System.Boolean |
shift |
|
| System.Boolean |
ctrl |
|
Move to the start of the current line of text.
Declaration
public void MoveToStartOfLine(bool shift, bool ctrl)
Parameters
| Type |
Name |
Description |
| System.Boolean |
shift |
|
| System.Boolean |
ctrl |
|
Declaration
public virtual void OnBeginDrag(PointerEventData eventData)
Parameters
| Type |
Name |
Description |
| UnityEngine.EventSystems.PointerEventData |
eventData |
|
Implements
UnityEngine.EventSystems.IBeginDragHandler.OnBeginDrag(UnityEngine.EventSystems.PointerEventData)
Declaration
public void OnControlClick()
Declaration
public override void OnDeselect(BaseEventData eventData)
Parameters
| Type |
Name |
Description |
| UnityEngine.EventSystems.BaseEventData |
eventData |
|
Overrides
UnityEngine.UI.Selectable.OnDeselect(UnityEngine.EventSystems.BaseEventData)
Declaration
protected override void OnDisable()
Overrides
UnityEngine.UI.Selectable.OnDisable()
Declaration
public virtual void OnDrag(PointerEventData eventData)
Parameters
| Type |
Name |
Description |
| UnityEngine.EventSystems.PointerEventData |
eventData |
|
Implements
UnityEngine.EventSystems.IDragHandler.OnDrag(UnityEngine.EventSystems.PointerEventData)
Declaration
protected override void OnEnable()
Overrides
UnityEngine.UI.Selectable.OnEnable()
Declaration
public virtual void OnEndDrag(PointerEventData eventData)
Parameters
| Type |
Name |
Description |
| UnityEngine.EventSystems.PointerEventData |
eventData |
|
Implements
UnityEngine.EventSystems.IEndDragHandler.OnEndDrag(UnityEngine.EventSystems.PointerEventData)
Declaration
Declaration
public virtual void OnPointerClick(PointerEventData eventData)
Parameters
| Type |
Name |
Description |
| UnityEngine.EventSystems.PointerEventData |
eventData |
|
Implements
UnityEngine.EventSystems.IPointerClickHandler.OnPointerClick(UnityEngine.EventSystems.PointerEventData)
Declaration
public override void OnPointerDown(PointerEventData eventData)
Parameters
| Type |
Name |
Description |
| UnityEngine.EventSystems.PointerEventData |
eventData |
|
Overrides
UnityEngine.UI.Selectable.OnPointerDown(UnityEngine.EventSystems.PointerEventData)
Declaration
public virtual void OnScroll(PointerEventData eventData)
Parameters
| Type |
Name |
Description |
| UnityEngine.EventSystems.PointerEventData |
eventData |
|
Implements
UnityEngine.EventSystems.IScrollHandler.OnScroll(UnityEngine.EventSystems.PointerEventData)
Declaration
public override void OnSelect(BaseEventData eventData)
Parameters
| Type |
Name |
Description |
| UnityEngine.EventSystems.BaseEventData |
eventData |
|
Overrides
UnityEngine.UI.Selectable.OnSelect(UnityEngine.EventSystems.BaseEventData)
Declaration
public virtual void OnSubmit(BaseEventData eventData)
Parameters
| Type |
Name |
Description |
| UnityEngine.EventSystems.BaseEventData |
eventData |
|
Implements
UnityEngine.EventSystems.ISubmitHandler.OnSubmit(UnityEngine.EventSystems.BaseEventData)
Declaration
public virtual void OnUpdateSelected(BaseEventData eventData)
Parameters
| Type |
Name |
Description |
| UnityEngine.EventSystems.BaseEventData |
eventData |
|
Implements
UnityEngine.EventSystems.IUpdateSelectedHandler.OnUpdateSelected(UnityEngine.EventSystems.BaseEventData)
Declaration
public void ProcessEvent(Event e)
Parameters
| Type |
Name |
Description |
| Event |
e |
|
Declaration
public virtual void Rebuild(CanvasUpdate update)
Parameters
| Type |
Name |
Description |
| UnityEngine.UI.CanvasUpdate |
update |
|
Implements
UnityEngine.UI.ICanvasElement.Rebuild(UnityEngine.UI.CanvasUpdate)
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()
Function to conveniently set the Font Asset of both Placeholder and Input Field text object.
Declaration
public void SetGlobalFontAsset(TMP_FontAsset fontAsset)
Parameters
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 |
| System.Single |
pointSize |
|
Update the visual text Text.
Declaration
protected void UpdateLabel()
Validate the specified input.
Declaration
protected char Validate(string text, int pos, char ch)
Parameters
| Type |
Name |
Description |
| System.String |
text |
|
| System.Int32 |
pos |
|
| System.Char |
ch |
|
Returns
| Type |
Description |
| System.Char |
|