本部分将介绍用于在虚拟现实、增强现实和混合现实应用程序中进行交互的所有 Unity 支持的输入设备。
可以通过旧版输入轴和按钮索引访问 XR 输入功能。此表概括了每个功能在每个平台上映射的内容。有关如何使用按钮/游戏杆轴的信息,请参阅有关传统游戏输入的文档。
功能用途 | FeatureType | 旧版输入索引 [L/R] | WMR | Oculus | GearVR | Daydream | OpenVR (Full) | Vive | OpenVR (Oculus) | OpenVR (WMR) |
---|---|---|---|---|---|---|---|---|---|---|
Primary2DAxis | 2D 轴 | [(1,2)/(4,5)] | 游戏杆 | 游戏杆 | 游戏杆 | 触控板 | [触控板/游戏杆] | 触控板 | 游戏杆 | 游戏杆 |
触发器 | 轴 | [9/10] | 触发器 | 触发器 | 触发器 | 触发器 | 触发器 | 触发器 | 触发器 | 触发器 |
握把 | 轴 | [11/12] | 握把 | 握把 | 握把 | 握把 | 握把 | 握把 | 握把 | |
IndexTouch | 轴 | [13/14] | 食指 - 近触控 | |||||||
ThumbTouch | 轴 | [15/16] | 拇指 - 近触控 | |||||||
Secondary2DAxis | 2DAxis | [(17,18)/(19,20)] | 触控板 | 触控板 | ||||||
IndexFinger | 轴 | [21/22] | 食指 | |||||||
MiddleFinger | 轴 | [23/24] | 中指 | |||||||
RingFinger | 轴 | [25/26] | 无名指 | |||||||
PinkyFinger | 轴 | [27/28] | 小指 | |||||||
CombinedTrigger | 轴 | [3/3] | CombinedTrigger | 组合触发器 | 组合触发器 | 组合触发器 | 组合触发器 | 组合触发器 | ||
PrimaryButton | 按钮 | [2/0] | [X/A] | 应用程序 | 主要 | 主要 | 主要 [Y/B] | 菜单 | ||
PrimaryTouch | 按钮 | [12/10] | [X/A] - 触控 | |||||||
SecondaryButton | 按钮 | [3/1] | [Y/B] | 备用 | 备用 [B/A] | |||||
SecondaryTouch | 按钮 | [13/11] | [Y/B] - 触控 | |||||||
GripButton | 按钮 | [4/5] | 握把 - 按下 | 握把 - 按下 | 握把 - 按下 | 握把 - 按下 | 握把 - 按下 | 握把 - 按下 | 握把 | |
TriggerButton | 按钮 | [14/15] | 触发器 - 按下 | 食指 - 触控 | 触发器 - 按下 | 触发器 - 按下 | 触发器 - 按下 | 触发器 - 按下 | 触发器 - 触控 | 触发器 - 按下 |
MenuButton | 按钮 | [6/7] | 菜单 | 开始 (6) | ||||||
Primary2DAxisClick | 按钮 | [8/9] | 游戏杆 - 单击 | 控制杆 - 单击 | 触控板 - 单击 | 触控板 - 单击 | StickOrPad - 按下 | StickOrPad - 按下 | StickOrPad - 按下 | 触控板 - 单击 |
Primary2DAxisTouch | 按钮 | [16/17] | 触控板 - 单击 | 控制杆 - 触控 | 触控板 - 触摸 | 触控板 - 触摸 | StickOrPad - 触控 | StickOrPad - 触控 | StickOrPad - 触控 | 触控板 - 触摸 |
Thumbrest | 按钮 | [18/19] | 触控板 - 触摸 | ThumbRest - 触控 |
可以使用上表中的相应旧版输入索引,通过旧版输入系统轮询 XR 输入功能。在 Edit > Settings > Input 中创建轴映射,为平台设备的功能添加从输入名称到轴索引的适当映射。可以使用 Input.GetAxis 或 Input.GetButton 通过传入现在映射的轴或按钮名称来检索按钮或轴值。
可以检索任何当前跟踪的 XRNode 的输入设备。如果在跟踪的 XRNode 上有一个有效的输入设备,Unity 可以将触觉数据传送到相应的输入设备,为佩戴者提供身临其境的反馈。Unity 可以将触觉数据作为具有幅度和持续时间的简单脉冲发送,或者作为数据缓冲区发送。
并非所有平台都支持所有类型的触觉,但您可以查询设备的触觉功能。以下示例获取右手的输入设备,检查设备是否具有触觉功能,然后在有触觉功能的情况下再现脉冲:
InputDevice device = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);
HapticCapabilities capabilities;
if(device.TryGetHapticCapabilities(out capabilities))
{
if(capabilities.supportsImpulse)
{
uint channel = 0;
float amplitude = 0.5f;
float duration = 1.0f;
device.SendHapticImpulse(channel, amplitude, duration);
}
}
注意:此代码示例使用 UnityEngine.XR
命名空间。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.