Mobile Keyboard
手机键盘
In most cases, Unity will handle keyboard input automatically for GUI elements but it is also easy to show the keyboard on demand from a script.
在大多数情况下,Unity将通过GUI元素自动处理键盘输入,但也容易通过脚本即时显示键盘.
GUI Elements
GUI元素
The keyboard will appear automatically when a user taps on editable GUI elements. Currently,GUI.TextField, GUI.TextArea and GUI.PasswordField will display the keyboard; see the GUI class documentation for further details.
当用户在可编辑GUI元素上点击键盘将自动显示.当前地,GUI.TextField,GUI.TextArea和GUI.PasswordField将显示键盘,参考GUI类文档获取更详细信息.
Manual Keyboard Handling
键盘处理手册
Use the TouchScreenKeyboard.Open() function to open the keyboard. Please see theTouchScreenKeyboard scripting reference for the parameters that this function takes.
使用TouchScreenKeyboard.Open()函数打开键盘.请查看TouchScreenKeyboard脚本参考和它参数的功能.
Keyboard Layout Options
键盘布局选项
The Keyboard supports the following options:
键盘支持下列选项:
Property: 属性: | Function: 功能 |
TouchScreenKeyboardType.Default 触摸屏键盘类型.默认 | Letters. Can be switched to keyboard with numbers and punctuation. 字母.可使用数字和标点符号切换到键盘 |
TouchScreenKeyboardType.ASCIICapable 触摸屏键盘类型.ASCII可用 | Letters. Can be switched to keyboard with numbers and punctuation. 字母.可使用数字和标点符号切换到键盘 |
TouchScreenKeyboardType.NumbersAndPunctuation 触摸屏键盘类型.数字和标点 | Numbers and punctuation. Can be switched to keyboard with letters. 数字和标点.可使用字母切换到键盘 |
触摸屏键盘类型.URL | Letters with slash and .com buttons. Can be switched to keyboard with numbers and punctuation. 倾斜字母和.com按钮.可使用数字和标点切换到键盘 |
TouchScreenKeyboardType.NumberPad 触摸屏键盘类型.平板数字 | Only numbers from 0 to 9. 仅从0到9的数字 |
TouchScreenKeyboardType.PhonePad 触摸屏键盘类型.平板电话 | Keyboard used to enter phone numbers. 用于输入电话数字的键盘 |
TouchScreenKeyboardType.NamePhonePad 触摸屏键盘类型.平板电话名字 | Letters. Can be switched to phone keyboard. 字母.可切换到电话键盘 |
TouchScreenKeyboardType.EmailAddress 触摸屏键盘类型.邮箱地址 | Letters with @ sign. Can be switched to keyboard with numbers and punctuation. 带@字符的字母.可用数字和标点切换到键盘 |
Text Preview
文本预览
By default, an edit box will be created and placed on top of the keyboard after it appears. This works as preview of the text that user is typing, so the text is always visible for the user. However, you can disable text preview by setting TouchScreenKeyboard.hideInput to true. Note that this works only for certain keyboard types and input modes. For example, it will not work for phone keypads and multi-line text input. In such cases, the edit box will always appear.TouchScreenKeyboard.hideInput is a global variable and will affect all keyboards.
默认,一个编辑框将创建和放置到键盘顶部.这是用户输入文本的预览,所以文本对于用户总是可见.然而,你可以通过设置触屏键盘->隐藏输入为ture禁用文本预览.注意,此仅工作在确定键盘类型和输入模式.例如,它将不工作在电话平板键盘和多行文本输入.在这种情况下,编辑框将总是显示.触屏键盘->隐藏输入是一个全局变量并且将影响所有键盘.
Visibility and Keyboard Size
可见性和键盘大小
There are three keyboard properties in TouchScreenKeyboard that determine keyboard visibility status and size on the screen.
这里有3种键盘属性在”触屏键盘”类以确定键盘在屏幕上的可见性状态和大小.
Property: 属性: | Function: 功能: |
Visible 可见性 | Returns true if the keyboard is fully visible on the screen and can be used to enter characters. 如果键盘在屏幕上完全可见且可用于输入字符,返回ture. |
Area 区域 | Returns the position and dimensions of the keyboard. 返回键盘的位置和规模 |
Active 活动 | Returns true if the keyboard is activated. This property is not static property. You must have a keyboard instance to use this property. 如果键盘是活动的返回ture.此属性不是静态属性.你必须有一个键盘使用此属性来实例. |
Note that TouchScreenKeyboard.area will return a Rect with position and size set to 0 until the keyboard is fully visible on the screen. You should not query this value immediately after TouchScreenKeyboard.Open(). The sequence of keyboard events is as follows:
注意,触屏键盘->区域将返回一个带有位置和大小为0的矩形直到键盘完全显示在屏幕上.你需要在TouchScreenKeyboard.Open()后立即查询此值.键盘事件序列如下:
1. TouchScreenKeyboard.Open() is called. TouchScreenKeyboard.active returns true.TouchScreenKeyboard.visible returns false. TouchScreenKeyboard.area returns (0, 0, 0, 0).
2. Keyboard slides out into the screen. All properties remain the same.
3. Keyboard stops sliding. TouchScreenKeyboard.active returns true.TouchScreenKeyboard.visible returns true. TouchScreenKeyboard.area returns real position and size of the keyboard.
调用TouchScreenKeyboard.Open()函数.TouchScreenKeyboard.active返回ture.TouchScreenKeyboard.visible返回false.TouchScreenKeyboard.area返回(0,0,0,0).
键盘滑出到屏幕上.所有属性相同.
键盘停止滑动.TouchScreenKeyboard.active 返回 true.TouchScreenKeyboard.visible 返回 true. TouchScreenKeyboard.area返回键盘真实位置和大小.
Secure Text Input
文本输入安全
It is possible to configure the keyboard to hide symbols when typing. This is useful when users are required to enter sensitive information (such as passwords). To manually open keyboard with secure text input enabled, use the following code:
可以配置当输入时键盘隐藏符号.这对当用户要输入敏感信息时非常有用(如密码).手动打开键盘文本输入安全,使用下列代码:
TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default, false, false, true);
Hiding text while typing
输入时隐藏文本
Alert keyboard
弹出框键盘
To display the keyboard with a black semi-transparent background instead of the classic opaque, call TouchScreenKeyboard.Open() as follows:
显示键盘为一个黑色半透明背景以替代经典的不透明,调用TouchScreenKeyboard.Open()如下:
TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default, false, false, true, true);
Classic keyboard
经典键盘
Alert keyboard
弹出框键盘