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 Button ID | Unity Axis ID | Unity Axis 値の範囲 |
---|---|---|---|---|---|
Left Controller Menu Button (1) | Button.Three | 押す | 2 | ||
Right Controller Menu Button (1) | Button.One | 押す | 0 | ||
Left Controller Trackpad (2) | Button.PrimaryThumbstick | 押す | 8 | ||
Right Controller Trackpad (2) | Button.SecondaryThumbstick | 押す | 9 | ||
Left Controller Trackpad (2) | Button.PrimaryThumbstick | 接触 | 16 | ||
Right Controller Trackpad (2) | Button.SecondaryThumbstick | 接触 | 17 | ||
Left Controller Trackpad (2) | Axis2D.PrimaryThumbstick | 水平移動 | 1 | –1.0 から 1.0 | |
Left Controller Trackpad (2) | Axis2D.PrimaryThumbstick | 垂直移動 | 2 | –1.0 から 1.0 | |
Right Controller Trackpad (2) | Axis2D.SecondaryThumbstick | 水平移動 | 4 | –1.0 から 1.0 | |
Right Controller Trackpad (2) | Axis2D.SecondaryThumbstick | 垂直移動 | 5 | –1.0 から 1.0 | |
Left Controller Trigger (7) | Axis1D.PrimaryIndexTrigger | 接触 | 14 | ||
Right Controller Trigger (7) | Axis1D.SecondaryIndexTrigger | 接触 | 15 | ||
Left Controller Trigger (7) | Axis1D.PrimaryIndexTrigger | 握る | 9 | 0.0 から 1.0 | |
Right Controller Trigger (7) | Axis1D.SecondaryIndexTrigger | 握る | 10 | 0.0 から 1.0 | |
Left Controller Grip Button (8) | Axis1D.PrimaryHandTrigger | 握る | 11 | 0.0 から 1.0 | |
Right Controller Grip Button (8) | Axis1D.SecondaryHandTrigger | 握る | 12 | 0.0 から 1.0 |
注意