text | 要编辑的文本。 |
keyboardType | 键盘类型(例如,任何文本、仅数字等)。 |
autocorrection | 是否应用自动更正? |
multiline | 可以输入多行文本吗? |
secure | 文本是否被掩盖(用于密码等)? |
alert | 键盘是否以警报模式打开? |
textPlaceholder | 如果不存在其他文本,则使用此文本。 |
characterLimit | 键盘输入字段的字符限制。0 = 无限。(仅限 Android 和 iOS) |
在屏幕上打开操作系统提供的原生键盘。
autocorrection
确定输入是否跟踪未知单词并向用户建议更合适的替换候选,除非用户明确覆盖操作,否则自动替换输入的文本。 multiline
确定用户是否可以输入多行文本。 secure
标识键盘是否用于密码。输入字段中的文本将对用户隐藏,除了最近输入的字符。键盘也可以在 alert
模式下打开。当键盘输入字段中没有其他文本时,将显示 placeholder
字符串。
其他资源:警报键盘
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { public string stringToEdit = "Hello World"; private TouchScreenKeyboard keyboard;
// Opens native keyboard void OnGUI() { stringToEdit = GUI.TextField(new Rect(10, 10, 200, 30), stringToEdit, 30);
if (GUI.Button(new Rect(10, 50, 200, 100), "Default")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default); } if (GUI.Button(new Rect(10, 150, 200, 100), "ASCIICapable")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.ASCIICapable); } if (GUI.Button(new Rect(10, 250, 200, 100), "Numbers and Punctuation")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.NumbersAndPunctuation); } if (GUI.Button(new Rect(10, 350, 200, 100), "URL")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.URL); } if (GUI.Button(new Rect(10, 450, 200, 100), "NumberPad")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.NumberPad); } if (GUI.Button(new Rect(10, 550, 200, 100), "PhonePad")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.PhonePad); } if (GUI.Button(new Rect(10, 650, 200, 100), "NamePhonePad")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.NamePhonePad); } if (GUI.Button(new Rect(10, 750, 200, 100), "EmailAddress")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.EmailAddress); } if (GUI.Button(new Rect(10, 850, 200, 100), "Social")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Social); } if (GUI.Button(new Rect(10, 950, 200, 100), "Search")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Search); } // Only supported on iOS if (GUI.Button(new Rect(10, 1050, 200, 100), "One Time Code")) { keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.OneTimeCode); } } }