Input 输入

Interface into the Input system.

输入系统的接口。

Use this class to read the axes set up in the Input Manager, and to access multi-touch/accelerometer data on mobile devices.

使用这个类能够读取输入管理器设置的按键,以及访问移动设备的多点触控或加速感应数据。

To read an axis use Input.GetAxis with one of the following default axes: "Horizontal" and "Vertical" are mapped to joystick, A, W, S, D and the arrow keys. "Mouse X" and "Mouse Y" are mapped to the mouse delta. "Fire1", "Fire2" "Fire3" are mapped to Ctrl, Alt, Cmd keys and three mouse or joystick buttons. New input axes can be added in the Input Manager.

想要读取轴向使用Input.GetAxis方法获取下列默认轴: "Horizontal" 和"Vertical" 映射于控制杆、A、W、S、D和箭头键(方向键)。 "Mouse X" 和"Mouse Y" 映射于鼠标,"Fire1", "Fire2" "Fire3"映射于键盘的Ctrl、Alt、Cmd键和鼠标中键或控制器的按钮。新的输入设置可以使用输入管理器来添加。

If you are using input for any kind of movement behaviour use Input.GetAxis. It gives you smoothed and configurable input that can be mapped to keyboard, joystick or mouse. Use Input.GetButton for action like events only. Don't use it for movement, Input.GetAxis will make the script code smaller and simpler.

如果你使用Input制作某种运动行为可以使用Input.GetAxis方法,它能够返回来自键盘、控制器或鼠标平缓并且可以设置的输入结果。使用Input.GetButton方法只用于像事件之类的动作。不要将它用于移动动作。Input.GetAxis方法可以使脚本代码更简洁。

Note also that the Input flags are not reset until "Update()", so its suggested you make all the Input Calls in the Update Loop.

注意:每次输入在"Update()"之前不会再更新,所以建议你将所有的输入调用都写在Update方法中。(Update循环中)

Mobile Devices:

移动设备:

iOS and Android devices are capable of tracking multiple fingers touching the screen simultaneously. You can access data on the status of each finger touching screen during the last frame by accessing the Input.touches property array.

iOS和Android设备能够支持多点触控。你可以通过Input.touches属性集合访问在最近一帧中触摸在屏幕上的每一根手指的状态数据。

As a device moves, its accelerometer hardware reports linear acceleration changes along the three primary axes in three-dimensional space. You can use this data to detect both the current orientation of the device (relative to the ground) and any immediate changes to that orientation.

当设备移动时,它们的加速感应器硬件将报告它们在三维空间中沿着三个主轴的线性加速变化数据。你可以使用这些数据检测设备当前的移动方向(相对于地面)和突然间的方向改 变。

Acceleration along each axis is reported directly by the hardware as G-force values. A value of 1.0 represents a load of about +1g along a given axis while a value of -1.0 represents -1g. If you hold the device upright (with the home button at the bottom) in front of you, the X axis is positive along the right, the Y axis is positive directly up, and the Z axis is positive pointing toward you.

硬件沿着某感应一轴加速就会立即返回重力值。如果值为1.0代表沿着给定轴的方向+1g的重力加速度,如果值为-1.0代表-1g的重力加速度。如果你保持设备垂直(主页键在下方)在你正前方,那么X轴就是指向你右侧的方向,Y轴指向正上方,Z轴就是你所面向的方向。

You can read the Input.acceleration property to get the accelerometer reading. You can also use the Input.deviceOrientation property to get a discrete evaluation of the device's orientation in three-dimensional space. Detecting a change in orientation can be useful if you want to create game behaviors when the user rotates the device to hold it differently.

你可以读取Input.acceleration属性获得设备的加速度信息。你也可以使用Input.deviceOrientation属性获取设备在三维空间中的方位偏移。检测方位变化在你想要制作游戏行为中会非常有用,当用户转动设备或拿着设备时它是不同的。

Note that the accelerometer hardware can be polled more than once per frame. To access all accelerometer samples since the last frame, you can read the Input.accelerationEvents property array. This can be useful when reconstructing player motions, feeding acceleration data into a predictor, or implementing other precise motion analysis.

注意:速度感应装置在每一帧中能够轮询多次,想访问上一帧的所有速度样本你可以读取Input.accelerationEvents属性集合。这在重组玩家动作中会非常有用。例如将加速数据放入一个预测器中或者实现其他一些精确的动作捕捉。

The Unity mobile devices input API is based on Apple's iOS API. It may help to learn more about the native API to better understand Unity's Input API. You can find Apple's input API documentation here:

Unity移动设备输入API是以苹果的iOS API为基础。学习一些原生API更有助于理解Unity的Input API。你可以查找苹果的Input API文档:

Programming Guide: Event Handling (Apple iPhone SDK documentation)

UITouch Class Reference (Apple iPhone SDK documentation)

NOTE: above links reference your locally installed iOS SDK Reference Documentation and will contain native ObjectiveC code. It is not necessary to understand these documents for using Unity iOS, but may be helpful to some!

注意:以上链接参考你本地安装的iOS SDK参考文档将包含ObjectiveC代码。你没有必要去弄明白这些文档怎么用于UnityiOS,但是能理解点更好。

Class Variables类变量

Class Functions类函数

最后修改:2011年10月6日 Thursday 18:06

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。