这是Unity 2018中的输入字段发生的情况
第1步:在这里,我们有一个基本的InputField
第2步:当我单击该字段时,底部会出现一个系统输入
第3步:单击输入后,出现键盘
如何直接打开键盘?从步骤1到3
答案 0 :(得分:0)
这是来自documantation的一些代码:
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);
}
}
}