简体   繁体   English

直接在Unity 2018中打开键盘

[英]Open keyboard directly in Unity 2018

This is happening with the input field in Unity 2018 这与Unity 2018中的输入字段一起发生

Step 1: Here, we have a basic InputField 第1步:在这里,我们有一个基本的InputField

在此输入图像描述

Step 2: When I click the field, one system input appears on the bottom 第2步:单击该字段时,底部会显示一个系统输入

在此输入图像描述

Step 3: After click that input the keyboard appears 第3步:点击该输入后,键盘出现

在此输入图像描述

How can I open the keyboard directly? 如何直接打开键盘? From step 1 to 3 从第1步到第3步

Use TouchScreenKeyboard.Open() . 使用TouchScreenKeyboard.Open()

Here is some code from documantation : 以下是来自documentmantation的一些代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM