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.
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 |
注意: