返回介绍

Input 输入

发布于 2019-12-18 15:37:53 字数 12564 浏览 932 评论 0 收藏 0

Namespace: UnityEngine

Description 描述

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属性集合。这在重组玩家动作中会非常有用。例如将加速数据放入一个预测器中或者实现其他一些精确的动作捕捉。

Static Variables 静态变量

accelerationLast measured linear acceleration of a device in three-dimensional space. (Read Only)
上一次测量的设备在三维空间中的线性加速度(只读)。
accelerationEventCountNumber of acceleration measurements which occurred during last frame.
上一帧发生的所测量的的加速度次数。
accelerationEventsReturns list of acceleration measurements which occurred during the last frame. (Read Only) (Allocates temporary variables).
返回上一帧测量的加速度数据列表(只读)(分配临时变量)
anyKeyIs any key or mouse button currently held down? (Read Only)
当前是否有任意键或鼠标键被按下(只读)?
anyKeyDownReturns true the first frame the user hits any key or mouse button. (Read Only)
在用户按下任意按键或鼠标按键首帧返回true(只读)。
compassProperty for accessing compass (handheld devices only). (Read Only)
访问指南针的属性(仅手持设备)。
compensateSensorsThis property controls if input sensors should be compensated for screen orientation.
该属性控制输入传感器在屏幕方向的补偿。
compositionCursorPosThe current text input position used by IMEs to open windows.
当前文本输入位置,使用于IME来打开窗口。
compositionStringThe current IME composition string being typed by the user.
当前用户正在输入的IME组合字符串。
deviceOrientationDevice physical orientation as reported by OS. (Read Only)
由操作系统所报告的设备的物理方向(只读)。
gyroReturns default gyroscope.
返回默认的陀螺仪。
imeCompositionModeControls enabling and disabling of IME input composition.
控制IME输入组合的启用和禁用。
imeIsSelectedDoes the user have an IME keyboard input source selected?
用户是否已选择IME键盘输入源?
inputStringReturns the keyboard input entered this frame. (Read Only)
返回在这一帧的键盘输入(只读)
locationProperty for accessing device location (handheld devices only). (Read Only)
用于访问设备位置信息(仅手持设备)(只读)。
mousePositionThe current mouse position in pixel coordinates. (Read Only)
在屏幕坐标空间当前鼠标的位置(只读)。
mouseScrollDeltaThe current mouse scroll delta. (Read Only)
当前鼠标滚动增量(只读)。
multiTouchEnabledProperty indicating whether the system handles multiple touches.
指示系统是否启用多点触控。
simulateMouseWithTouchesEnables/Disables mouse simulation with touches. By default this option is enabled.
启用/禁用鼠标模拟触摸。默认情况下启用此项。
touchCountNumber of touches. Guaranteed not to change throughout the frame. (Read Only)
触摸的数量。每一帧之内都一定不会改变(只读)
touchesReturns list of objects representing status of all touches during last frame. (Read Only) (Allocates temporary variables).
返回代表上一帧所有的触摸状态的对象列表(只读)(分配临时变量)
touchSupportedReturns whether the device on which application is currently running supports touch input.
返回设备是否在当前运行的应用程序支持触摸输入。

Static Functions 静态函数

GetAccelerationEventReturns specific acceleration measurement which occurred during last frame. (Does not allocate temporary variables).
返回上一帧发生的指定的加速度测量(不允许分配临时变量)。
GetAxisReturns the value of the virtual axis identified by axisName.
根据axisName名称返回虚拟输入轴中的值。
GetAxisRawReturns the value of the virtual axis identified by axisName with no smoothing filtering applied.
通过axisName名称返回一个不使用平滑滤波器的虚拟轴值。
GetButtonReturns true while the virtual button identified by buttonName is held down.
当由'buttonname”确定的虚拟按键被按下时,返回true。
GetButtonDownReturns true during the frame the user pressed down the virtual button identified by buttonName.
在用户按下由buttonName名称确定的虚拟按钮的那一帧返回true。
GetButtonUpReturns true the first frame the user releases the virtual button identified by buttonName.
在用户释放根据buttonName名称的虚拟按钮时返回true。
GetJoystickNamesReturns an array of strings describing the connected joysticks.
返回一个用来描述已连接的摇杆的字符串数组。
GetKeyReturns true while the user holds down the key identified by name. Think auto fire.
当用户按下由name名称确定的按键时,然后true。想想自动开火。
GetKeyDownReturns true during the frame the user starts pressing down the key identified by name.
当用户按下指定名称的按键时的那一帧返回true。
GetKeyUpReturns true during the frame the user releases the key identified by name.
在用户释放给定名字的按键的那一帧返回true。
GetMouseButtonReturns whether the given mouse button is held down.
当指定的鼠标按钮被按下时返回true。
GetMouseButtonDownReturns true during the frame the user pressed the given mouse button.
在用户按下指定鼠标按键的那一帧返回true。
GetMouseButtonUpReturns true during the frame the user releases the given mouse button.
在用户释放指定鼠标按键的那一帧返回true。
GetTouchReturns object representing status of a specific touch. (Does not allocate temporary variables).
返回一个存放触摸信息的对象(不允许分配临时变量)。
IsJoystickPreconfiguredDetermine whether a particular joystick model has been preconfigured by Unity. (Linux-only).
确定Unity是否一个特定的操纵杆模型已预先配置。(仅Linux)。
ResetInputAxesResets all input. After ResetInputAxes all axes return to 0 and all buttons return to 0 for one frame.
在一帧中重置所有的输入,重置输入指令之后所有的方向轴都被设置为0并且所有的按键都被设置为0。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文