Android unity 按下输入框不显示键盘?
Android Keyboard does not show when pressing input field in unity?
我在 unity 中有一个简单的场景,其中有一个输入字段。当我在我的 Android 设备中 运行 我的场景并按下输入字段时, android 键盘不显示。我使用 Unity Remote 5 应用程序通过 USB 连接到我的笔记本电脑。
这是我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class InputNumber : MonoBehaviour {
public InputField input;
// Use this for initialization
void Start () {
if (input)
{
TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default, false, false, true);
}
input.keyboardType = TouchScreenKeyboardType.NumberPad;
}
// Update is called once per frame
void Update () {
}
}
您需要资产商店 Unity standard asset
包中的 Cross-Platform-Input
资产。这是免费的,一旦导入到您的项目中,文本字段就会独立运行。只需导入它并再次尝试 phone
那么你将不需要:
if (input)
{
TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default, false, false, true);
}
input.keyboardType = TouchScreenKeyboardType.NumberPad;
Unitys mobile class 只会在您点击该字段时打开键盘。无需额外编码。
使用 InputField
组件时,您 不需要 需要 TouchScreenKeyboard.Open
手动打开键盘。单击 InputField
后,它将自行打开。删除不必要的 TouchScreenKeyboard.Open
代码。
I am connecting via USB to my laptop using Unity Remote 5 app.
这就是问题所在。
InputField
组件只会在您 在设备 上构建和 运行 程序时打开键盘。 Unity Remote 5 仅用于在编辑器上编程时检测屏幕上的触摸并读取 GPS 和加速计传感器等传感器。有关 Unity Remote 5 支持的功能,请参阅 post。
此外,TouchScreenKeyboard.Open
也无法在编辑器中使用。您必须在移动设备上构建并 运行 它才能工作,但此处不需要 TouchScreenKeyboard.Open
。只需构建游戏并将其部署到您的设备,当您单击 InputField 时,键盘就会打开。
无需调用 TouchScreenKeyboard.Open() 方法。如果您 运行 在 Unity Remote 应用程序中使用本机键盘,则不会显示本机键盘。但是,一旦您从文件 > 构建设置 > 构建或文件 > 构建和 运行.
构建和 运行 应用程序,它就会显示在触摸输入字段中
我在 unity 中有一个简单的场景,其中有一个输入字段。当我在我的 Android 设备中 运行 我的场景并按下输入字段时, android 键盘不显示。我使用 Unity Remote 5 应用程序通过 USB 连接到我的笔记本电脑。
这是我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class InputNumber : MonoBehaviour {
public InputField input;
// Use this for initialization
void Start () {
if (input)
{
TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default, false, false, true);
}
input.keyboardType = TouchScreenKeyboardType.NumberPad;
}
// Update is called once per frame
void Update () {
}
}
您需要资产商店 Unity standard asset
包中的 Cross-Platform-Input
资产。这是免费的,一旦导入到您的项目中,文本字段就会独立运行。只需导入它并再次尝试 phone
那么你将不需要:
if (input)
{
TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default, false, false, true);
}
input.keyboardType = TouchScreenKeyboardType.NumberPad;
Unitys mobile class 只会在您点击该字段时打开键盘。无需额外编码。
使用 InputField
组件时,您 不需要 需要 TouchScreenKeyboard.Open
手动打开键盘。单击 InputField
后,它将自行打开。删除不必要的 TouchScreenKeyboard.Open
代码。
I am connecting via USB to my laptop using Unity Remote 5 app.
这就是问题所在。
InputField
组件只会在您 在设备 上构建和 运行 程序时打开键盘。 Unity Remote 5 仅用于在编辑器上编程时检测屏幕上的触摸并读取 GPS 和加速计传感器等传感器。有关 Unity Remote 5 支持的功能,请参阅
此外,TouchScreenKeyboard.Open
也无法在编辑器中使用。您必须在移动设备上构建并 运行 它才能工作,但此处不需要 TouchScreenKeyboard.Open
。只需构建游戏并将其部署到您的设备,当您单击 InputField 时,键盘就会打开。
无需调用 TouchScreenKeyboard.Open() 方法。如果您 运行 在 Unity Remote 应用程序中使用本机键盘,则不会显示本机键盘。但是,一旦您从文件 > 构建设置 > 构建或文件 > 构建和 运行.
构建和 运行 应用程序,它就会显示在触摸输入字段中