【问题标题】:Open keyboard directly in Unity 2018在 Unity 2018 中直接打开键盘
【发布时间】:2019-04-20 08:07:13
【问题描述】:

Unity 2018 中的输入字段会发生这种情况

第 1 步:在这里,我们有一个基本的 InputField

第 2 步:当我单击该字段时,底部会出现一个系统输入

第 3 步:点击该输入后出现键盘

如何直接打开键盘?从第 1 步到第 3 步

【问题讨论】:

    标签: c# unity3d input


    【解决方案1】:

    使用TouchScreenKeyboard.Open()

    这是来自文档的一些代码:

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

    【讨论】:

    • 即使使用 GUI.TextField 也是如此。可能是安卓版本的原因
    猜你喜欢
    • 2013-08-27
    • 1970-01-01
    • 1970-01-01
    • 2014-08-21
    • 2011-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多