Class TMP_InputField
Editable text input field.
Inheritance
TMP_InputField
Inherited Members
Component.GetComponent<T>()
Component.TryGetComponent<T>(out T)
Component.GetComponentInChildren<T>()
Component.GetComponentsInChildren<T>()
Component.GetComponentInParent<T>()
Component.GetComponentsInParent<T>()
Component.GetComponents<T>()
Object.GetHashCode()
Object.InstantiateAsync<T>(T)
Object.InstantiateAsync<T>(T, Transform)
Object.InstantiateAsync<T>(T, Vector3, Quaternion)
Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)
Object.Instantiate<T>(T)
Object.Instantiate<T>(T, Vector3, Quaternion)
Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
Object.Instantiate<T>(T, Transform)
Object.DestroyObject(Object)
Object.FindObjectsOfType<T>()
Object.FindObjectsByType<T>(FindObjectsSortMode)
Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
Object.FindObjectOfType<T>()
Object.FindFirstObjectByType<T>()
Object.FindAnyObjectByType<T>()
Object.FindFirstObjectByType<T>(FindObjectsInactive)
Object.FindAnyObjectByType<T>(FindObjectsInactive)
Namespace: TMPro
Assembly: Unity.TextMeshPro.dll
[AddComponentMenu("UI/TextMeshPro - Input Field", 11)]
[HelpURL("https://docs.unity3d.com/Packages/com.unity.ugui@2.0/manual/TextMeshPro/index.html")]
public class TMP_InputField : Selectable, IMoveHandler, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, IUpdateSelectedHandler, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerClickHandler, ISubmitHandler, ICancelHandler, 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 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
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
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
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
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
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
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 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()
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 |
|
Transition the Selectable to the entered state.
Declaration
protected override void DoStateTransition(Selectable.SelectionState state, bool instant)
Parameters
Overrides
Declaration
public void ForceLabelUpdate()
Callback sent when this ICanvasElement has completed Graphic rebuild.
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()
Callback sent when this ICanvasElement has completed layout.
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 |
|
Called by a BaseInputModule before a drag is started.
Declaration
public virtual void OnBeginDrag(PointerEventData eventData)
Parameters
Declaration
public virtual void OnCancel(BaseEventData eventData)
Parameters
Declaration
public void OnControlClick()
Unset selection and transition to appropriate state.
Declaration
public override void OnDeselect(BaseEventData eventData)
Parameters
Overrides
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;// Required when using Event data.
public class ExampleClass : MonoBehaviour, IDeselectHandler //This Interface is required to receive OnDeselect callbacks.
{
public void OnDeselect(BaseEventData data)
{
Debug.Log("Deselected");
}
}
Declaration
protected override void OnDisable()
Overrides
When dragging is occurring this will be called every time the cursor is moved.
Declaration
public virtual void OnDrag(PointerEventData eventData)
Parameters
Declaration
protected override void OnEnable()
Overrides
Called by a BaseInputModule when a drag is ended.
Declaration
public virtual void OnEndDrag(PointerEventData eventData)
Parameters
Declaration
Determine in which of the 4 move directions the next selectable object should be found.
Declaration
public override void OnMove(AxisEventData eventData)
Parameters
Overrides
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;// Required when using Event data.
public class ExampleClass : MonoBehaviour, IMoveHandler
{
//When the focus moves to another selectable object, Invoke this Method.
public void OnMove(AxisEventData eventData)
{
//Assigns the move direction and the raw input vector representing the direction from the event data.
MoveDirection moveDir = eventData.moveDir;
Vector2 moveVector = eventData.moveVector;
//Displays the information in the console
Debug.Log(moveDir + ", " + moveVector);
}
}
Use this callback to detect clicks.
Declaration
public virtual void OnPointerClick(PointerEventData eventData)
Parameters
Evaluate current state and transition to pressed state.
Declaration
public override void OnPointerDown(PointerEventData eventData)
Parameters
Overrides
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;// Required when using Event data.
public class ExampleClass : MonoBehaviour, IPointerDownHandler// required interface when using the OnPointerDown method.
{
//Do this when the mouse is clicked over the selectable object this script is attached to.
public void OnPointerDown(PointerEventData eventData)
{
Debug.Log(this.gameObject.name + " Was Clicked.");
}
}
Declaration
public virtual void OnScroll(PointerEventData eventData)
Parameters
Set selection and transition to appropriate state.
Declaration
public override void OnSelect(BaseEventData eventData)
Parameters
Overrides
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;// Required when using Event data.
public class ExampleClass : MonoBehaviour, ISelectHandler// required interface when using the OnSelect method.
{
//Do this when the selectable UI object is selected.
public void OnSelect(BaseEventData eventData)
{
Debug.Log(this.gameObject.name + " was selected");
}
}
Declaration
public virtual void OnSubmit(BaseEventData eventData)
Parameters
Declaration
public virtual void OnUpdateSelected(BaseEventData eventData)
Parameters
Declaration
protected override void OnValidate()
Overrides
Declaration
public void ProcessEvent(Event e)
Parameters
Type |
Name |
Description |
Event |
e |
|
Rebuild the element for the given stage.
Declaration
public virtual void Rebuild(CanvasUpdate update)
Parameters
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