Version: 2022.1
public static TouchScreenKeyboard Open (string text, TouchScreenKeyboardType keyboardType= TouchScreenKeyboardType.Default, bool autocorrection= true, bool multiline= false, bool secure= false, bool alert= false, string textPlaceholder= "", int characterLimit= 0);

参数

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); } } }