Version: 2017.1
Oculus 的输入
变换组件

Input for OpenVR controllers

To facilitate Unity Editor native support for tracked controllers supported by OpenVR, the Unity VR subsystem presents VR controller inputs as separate joysticks. You can access their axis and button values with the UnityEngine.Input class.

By using OpenVR’s controller abstraction, the Unity Editor presents axis and button states in a hardware-agnostic approach (that is, it doesn’t refer to any specific hardware, but uses generic terms). However, for the sake of clarity, the axis and button mappings given below are for the two supported controller types: the HTC Vive controllers, and the Oculus Touch Controllers.

命名约定和检测

When properly configured and connected, a pair of Oculus Touch Controllers or a pair of HTC Vive controllers appear in the list returned by UnityEngine.Input.GetJoystickNames() as OpenVR Controller - Left and OpenVR Controller - Right. When available, these controllers appear highlighted in green in the SteamVR status window.

Unity script code can test for the availability of these controllers by periodically checking for their presence in the list of joystick names. When the controllers are turned off or have their batteries removed, an empty string replaces their name in the list returned by UnityEngine.Input.GetJoystickNames(). When the controllers are turned on again, their name appears in the list of returned joysticks.

Unity Input system mappings

Diagram of Vive controllers

(Image courtesy of developer.viveport.com)
(Image courtesy of developer.viveport.com)

Diagram of Oculus Touch Controllers

(Image courtesy of developer.oculus.com)
(Image courtesy of developer.oculus.com)
Vive Controller Hardware Feature Touch Controller Hardware Feature 交互类型 Unity 按钮 ID Unity 轴 ID Unity 轴值范围
左控制器菜单按钮 (1) Button.Three 按压 2
右控制器菜单按钮 (1) Button.One 按压 0
左控制器触控板 (2) Button.PrimaryThumbstick 按压 8
右控制器触控板 (2) Button.SecondaryThumbstick 按压 9
左控制器触控板 (2) Button.PrimaryThumbstick 触控 16
右控制器触控板 (2) Button.SecondaryThumbstick 触控 17
左控制器触控板 (2) Axis2D.PrimaryThumbstick 水平移动 1 –1.0 到 1.0
左控制器触控板 (2) Axis2D.PrimaryThumbstick 垂直移动 2 –1.0 到 1.0
右控制器触控板 (2) Axis2D.SecondaryThumbstick 水平移动 4 –1.0 到 1.0
右控制器触控板 (2) Axis2D.SecondaryThumbstick 垂直移动 5 –1.0 到 1.0
左控制器触发器 (7) Axis1D.PrimaryIndexTrigger 触控 14
右控制器触发器 (7) Axis1D.SecondaryIndexTrigger 触控 15
左控制器触发器 (7) Axis1D.PrimaryIndexTrigger 挤压 9 0.0 到 1.0
右控制器触发器 (7) Axis1D.SecondaryIndexTrigger 挤压 10 0.0 到 1.0
左控制器握把按钮 (8) Axis1D.PrimaryHandTrigger 挤压 11 0.0 到 1.0
右控制器握把按钮 (8) Axis1D.SecondaryHandTrigger 挤压 12 0.0 到 1.0

注意:

  • Touch events differ between platforms:
    • Touch events related to the HTC Vive controller’s trigger are only generated once the user begins squeezing the trigger.
    • Touch events on the Oculus Touch’s trigger occur when a touch is detected - no squeeze is necessary.
  • The grip trigger differs between platforms:
    • The HTC Vive controller has grip buttons on either side but both map to the same axis. The value is 0.0 when not pressed and 1.0 when pressed with no intermediate values possible.
    • The grip on the Oculus Touch Controller is an analog trigger with a range from 0.0 to 1.0.
  • Any hardware features not listed in the table above are not exposed through the OpenVR API and are therefore not exposed through Unity’s input system.
Oculus 的输入
变换组件