Class TMP_InputField
Editable text input field.
Inheritance
Object
Component
Behaviour
MonoBehaviour
UIBehaviour
Selectable
TMP_InputField
Implements
IMoveHandler
IPointerDownHandler
IPointerUpHandler
IPointerEnterHandler
IPointerExitHandler
ISelectHandler
IDeselectHandler
IUpdateSelectedHandler
IBeginDragHandler
IDragHandler
IEndDragHandler
IPointerClickHandler
ISubmitHandler
ICanvasElement
ILayoutElement
IScrollHandler
IEventSystemHandler
Inherited Members
Selectable.s_Selectables
Selectable.s_SelectableCount
Selectable.m_CurrentIndex
Selectable.AllSelectablesNoAlloc(Selectable[])
Selectable.Awake()
Selectable.OnCanvasGroupChanged()
Selectable.IsInteractable()
Selectable.OnDidApplyAnimationProperties()
Selectable.OnTransformParentChanged()
Selectable.InstantClearState()
Selectable.FindSelectableOnLeft()
Selectable.FindSelectableOnRight()
Selectable.FindSelectableOnUp()
Selectable.FindSelectableOnDown()
Selectable.OnMove(AxisEventData)
Selectable.IsHighlighted()
Selectable.IsPressed()
Selectable.OnPointerUp(PointerEventData)
Selectable.OnPointerEnter(PointerEventData)
Selectable.OnPointerExit(PointerEventData)
Selectable.Select()
Selectable.allSelectablesArray
Selectable.allSelectableCount
Selectable.allSelectables
Selectable.navigation
Selectable.transition
Selectable.colors
Selectable.spriteState
Selectable.animationTriggers
Selectable.targetGraphic
Selectable.interactable
Selectable.image
Selectable.animator
Selectable.currentSelectionState
UIBehaviour.Start()
UIBehaviour.OnDestroy()
UIBehaviour.IsActive()
UIBehaviour.OnRectTransformDimensionsChange()
UIBehaviour.OnBeforeTransformParentChanged()
UIBehaviour.OnCanvasHierarchyChanged()
UIBehaviour.IsDestroyed()
MonoBehaviour.IsInvoking()
MonoBehaviour.CancelInvoke()
MonoBehaviour.StopCoroutine(Coroutine)
MonoBehaviour.StopAllCoroutines()
MonoBehaviour.useGUILayout
MonoBehaviour.runInEditMode
Behaviour.enabled
Behaviour.isActiveAndEnabled
Component.GetComponent<T>()
Component.TryGetComponent<T>(out T)
Component.GetComponentInChildren<T>()
Component.GetComponentsInChildren<T>()
Component.GetComponentInParent<T>()
Component.GetComponentsInParent<T>()
Component.GetComponents<T>()
Component.transform
Component.gameObject
Component.tag
Object.GetInstanceID()
Object.GetHashCode()
Object.Instantiate(Object, Vector3, Quaternion)
Object.Instantiate(Object, Vector3, Quaternion, Transform)
Object.Instantiate(Object)
Object.Instantiate(Object, Transform)
Object.Instantiate<T>(T)
Object.Instantiate<T>(T, Vector3, Quaternion)
Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
Object.Instantiate<T>(T, Transform)
Object.Destroy(Object)
Object.DestroyImmediate(Object)
Object.DontDestroyOnLoad(Object)
Object.DestroyObject(Object)
Object.FindObjectsOfType<T>()
Object.FindObjectOfType<T>()
Object.ToString()
Object.name
Object.hideFlags
Namespace: TMPro
Assembly: Unity.TextMeshPro.dll
[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, ILayoutElement, IScrollHandler, IEventSystemHandler
Constructors
Declaration
protected TMP_InputField()
Fields
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
Type |
Description |
UIVertex[] |
|
Declaration
[SerializeField]
protected TMP_FontAsset m_GlobalFontAsset
Field Value
Declaration
[SerializeField]
protected TMP_InputValidator m_InputValidator
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
Type |
Description |
RectTransform |
|
Declaration
[SerializeField]
protected bool m_ResetOnDeActivation
Field Value
Declaration
[SerializeField]
protected float m_ScrollSensitivity
Field Value
Declaration
protected TouchScreenKeyboard m_SoftKeyboard
Field Value
Type |
Description |
TouchScreenKeyboard |
|
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
Type |
Description |
RectMask2D |
|
m_TextComponentRectTransform
Declaration
protected RectTransform m_TextComponentRectTransform
Field Value
Type |
Description |
RectTransform |
|
m_TextViewport
Declaration
[SerializeField]
protected RectTransform m_TextViewport
Field Value
Type |
Description |
RectTransform |
|
m_TextViewportRectMask
Declaration
protected RectMask2D m_TextViewportRectMask
Field Value
Type |
Description |
RectMask2D |
|
Declaration
[SerializeField]
protected Scrollbar m_VerticalScrollbar
Field Value
Type |
Description |
Scrollbar |
|
Declaration
[SerializeField]
protected TMP_ScrollbarEventHandler m_VerticalScrollbarEventHandler
Field Value
m_isRichTextEditingAllowed
Declaration
[SerializeField]
protected bool m_isRichTextEditingAllowed
Field Value
Declaration
protected bool m_isSelectAll
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
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
See ILayoutElement.flexibleWidth.
Declaration
public virtual float flexibleWidth { get; }
Property Value
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
isRichTextEditingAllowed
Is Rich Text editing allowed?
Declaration
public bool isRichTextEditingAllowed { get; set; }
Property Value
Declaration
public TouchScreenKeyboardType keyboardType { get; set; }
Property Value
Type |
Description |
TouchScreenKeyboardType |
|
See ILayoutElement.layoutPriority.
Declaration
public virtual int layoutPriority { get; }
Property Value
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
See ILayoutElement.minWidth.
Declaration
public virtual float minWidth { get; }
Property Value
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
Get the displayed with of all input characters.
Declaration
public virtual float preferredWidth { get; }
Property Value
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 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
Type |
Description |
RectTransform |
|
Declaration
public Scrollbar verticalScrollbar { get; set; }
Property Value
Type |
Description |
Scrollbar |
|
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()
See ILayoutElement.CalculateLayoutInputVertical.
Declaration
public virtual void CalculateLayoutInputVertical()
Declaration
protected void ClampCaretPos(ref int pos)
Parameters
Type |
Name |
Description |
int |
pos |
|
Declaration
protected void ClampStringPos(ref int pos)
Parameters
Type |
Name |
Description |
int |
pos |
|
Declaration
public void DeactivateInputField(bool clearSelection = false)
Parameters
Type |
Name |
Description |
bool |
clearSelection |
|
Declaration
protected override void DoStateTransition(Selectable.SelectionState state, bool instant)
Parameters
Type |
Name |
Description |
Selectable.SelectionState |
state |
|
bool |
instant |
|
Overrides
Declaration
public void ForceLabelUpdate()
Declaration
public virtual void GraphicUpdateComplete()
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()
MoveTextEnd(bool)
Move to the end of the text.
Declaration
public void MoveTextEnd(bool shift)
Parameters
Type |
Name |
Description |
bool |
shift |
|
MoveTextStart(bool)
Move to the start of the text.
Declaration
public void MoveTextStart(bool shift)
Parameters
Type |
Name |
Description |
bool |
shift |
|
Move to the end of the current line of text.
Declaration
public void MoveToEndOfLine(bool shift, bool ctrl)
Parameters
Type |
Name |
Description |
bool |
shift |
|
bool |
ctrl |
|
Move to the start of the current line of text.
Declaration
public void MoveToStartOfLine(bool shift, bool ctrl)
Parameters
Type |
Name |
Description |
bool |
shift |
|
bool |
ctrl |
|
Declaration
public virtual void OnBeginDrag(PointerEventData eventData)
Parameters
Type |
Name |
Description |
PointerEventData |
eventData |
|
Declaration
public void OnControlClick()
Declaration
public override void OnDeselect(BaseEventData eventData)
Parameters
Type |
Name |
Description |
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 |
PointerEventData |
eventData |
|
Declaration
protected override void OnEnable()
Overrides
UnityEngine.UI.Selectable.OnEnable()
Declaration
public virtual void OnEndDrag(PointerEventData eventData)
Parameters
Type |
Name |
Description |
PointerEventData |
eventData |
|
Declaration
Declaration
public virtual void OnPointerClick(PointerEventData eventData)
Parameters
Type |
Name |
Description |
PointerEventData |
eventData |
|
Declaration
public override void OnPointerDown(PointerEventData eventData)
Parameters
Type |
Name |
Description |
PointerEventData |
eventData |
|
Overrides
UnityEngine.UI.Selectable.OnPointerDown(UnityEngine.EventSystems.PointerEventData)
Declaration
public virtual void OnScroll(PointerEventData eventData)
Parameters
Type |
Name |
Description |
PointerEventData |
eventData |
|
Declaration
public override void OnSelect(BaseEventData eventData)
Parameters
Type |
Name |
Description |
BaseEventData |
eventData |
|
Overrides
UnityEngine.UI.Selectable.OnSelect(UnityEngine.EventSystems.BaseEventData)
Declaration
public virtual void OnSubmit(BaseEventData eventData)
Parameters
Type |
Name |
Description |
BaseEventData |
eventData |
|
Declaration
public virtual void OnUpdateSelected(BaseEventData eventData)
Parameters
Type |
Name |
Description |
BaseEventData |
eventData |
|
Declaration
protected override void OnValidate()
Overrides
Declaration
public void ProcessEvent(Event e)
Parameters
Type |
Name |
Description |
Event |
e |
|
Declaration
public virtual void Rebuild(CanvasUpdate update)
Parameters
Type |
Name |
Description |
CanvasUpdate |
update |
|
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()
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 |
float |
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
Implements
UnityEngine.EventSystems.IMoveHandler
UnityEngine.EventSystems.IPointerDownHandler
UnityEngine.EventSystems.IPointerUpHandler
UnityEngine.EventSystems.IPointerEnterHandler
UnityEngine.EventSystems.IPointerExitHandler
UnityEngine.EventSystems.ISelectHandler
UnityEngine.EventSystems.IDeselectHandler
UnityEngine.EventSystems.IUpdateSelectedHandler
UnityEngine.EventSystems.IBeginDragHandler
UnityEngine.EventSystems.IDragHandler
UnityEngine.EventSystems.IEndDragHandler
UnityEngine.EventSystems.IPointerClickHandler
UnityEngine.EventSystems.ISubmitHandler
UnityEngine.UI.ICanvasElement
UnityEngine.UI.ILayoutElement
UnityEngine.EventSystems.IScrollHandler
UnityEngine.EventSystems.IEventSystemHandler