TBInput
Overview
A wrapper class for interfacing with VR input devices on all supported TButt platforms.
Dependencies
Platform must be set using TBEditorBuildSettings
tool, and a TBCore
object must be in your scene.
Setup
Anywhere in your project that you would reference an input function from a native SDK should be replaced with an equivalent call to TBInput
.
Reference
Button Presses
Check if buttons are being pressed by passing a TBInput.Button
through the following button functions:
Function | Description |
---|---|
bool GetButtonDown(TBInput.Button button, TBInput.Controller controller = TBInput.Controller.Active) |
Returns true if the provided button was pressed. |
bool GetButtonUp(TBInput.Button button, TBInput.Controller controller = TBInput.Controller.Active) |
Returns true if the provided button was released. |
bool GetButton(TBInput.Button button, TBInput.Controller controller = TBInput.Controller.Active) |
Returns true while the provided button is pressed. |
Touches
Check for touches are being pressed by passing a TBInput.Button
with support for Touch through the following touch functions:
Function | Description |
---|---|
bool GetTouchDown(TBInput.Button button, TBInput.Controller controller = TBInput.Controller.Active) |
Returns true if the provided button was touched. |
bool GetTouchUp(TBInput.Button button, TBInput.Controller controller = TBInput.Controller.Active) |
Returns true if the provided button was touched. |
bool GetTouch(TBInput.Button button, TBInput.Controller controller = TBInput.Controller.Active) |
Returns true while the provided button is touched. |
Analog Inputs
Check for analog inputs by passing a TBInput.Button
with support for Axis1D or Axis2D through the following functions:
Function | Description |
---|---|
float GetAxis1D(TBInput.Button button, TBInput.Controller controller = TBInput.Controller.Active) |
Returns a float between 0 and 1. |
Vector2 GetAxis2D(TBInput.Button button, TBInput.Controller controller = TBInput.Controller.Active) |
Returns a Vector2 between Vector2(-1,-1) and Vector2(1,1) |
Note: TButt handles normalizing analog inputs to return within a standardized range across all platforms, so you can assume they’ll behave the same way.
Functionality
Check whether or not a given TBInput.Button
supports the requested input data type with its current configuration and active SDK:
Function | Description |
---|---|
bool SupportsButton(TBInput.Button button, TBInput.Controller controller = TBInput.Controller.Active) |
Returns true if the button supports button press data on the controller. |
bool SupportsTouch(TBInput.Button button, TBInput.Controller controller = TBInput.Controller.Active) |
Returns true if the button supports touch on the controller. |
bool SupportsAxis1D(TBInput.Button button, TBInput.Controller controller = TBInput.Controller.Active) |
Returns true if the button supports analog trigger data on the controller. |
bool SupportsAxis2D(TBInput.Button button, TBInput.Controller controller = TBInput.Controller.Active) |
Returns true if the button supports analog position data on the controller. |
TBInput.Controller GetActiveController() |
Returns the active controller (based on the active ControlType ). |
bool ControllerHasRumbleSupport(TBInput.Controller controller) |
True if the specified controller supports rumble. |
string GetControllerName(TBInput.Controller) |
Returns the name of the physical controller as defined in TButt’s internal config files. |
VRController GetControllerModel(TBInput.Controller) |
Returns the model of the controller as recognized by TButt. This is a type-safe value suitable for if or switch statements. |
Control Types
Function | Description |
---|---|
SetActiveControlType(TBInput.ControlType) |
Sets the active ControlType . |
TBInput.ControlType GetActiveControlType() |
Returns the active ControlType . |
TBInput.Mobile3DOFHandedness Get3DOFHandedness() |
Returns the player’s handedness preference as reported by the active SDK. |
Motion
You can access motion data for controllers that support it by passing a TBInput.Controller
to the following functions:
Function | Description |
---|---|
Vector3 GetPosition(TBInput.Controller = TBInput.Controller.Active) |
Returns the position of the controller in tracking space as reported by the SDK. |
Quaternion GetRotation(TBInput.Controller = TBInput.Controller.Active) |
Returns the rotation of the controller in tracking space as reported by the SDK. |
Vector3 GetVelocity(TBInput.Controller = TBInput.Controller.Active) |
Returns the velocity of the controller as reported by the SDK. |
Vector3 GetAngularVelocity(TBInput.Controller = TBInput.Controller.Active) |
Returns the angular velocity of the controller as reported by the SDK. |
Vector3 GetAcceleration(TBInput.Controller = TBInput.Controller.Active) |
Returns the acceleration of the controller as reported by the SDK. |
Rumble / Haptics
You can set rumble motor values by passing a TBInput.Controller
to the following functions (when supported by the controller):
Function | Description |
---|---|
SetRumble(TBInput.Controller controller, float amount = 0) |
Sets the controller’s rumble for this frame. Amount between 0 and 1. |
StartRumblePulse(TBInput.Controller controller = TBInput.Controller.Active, float strength = 0.5f, float length = 0.2f) |
Makes the controller rumble for the specified strength and time. Strength specified from 0 to 1, or using preset RumblePulse enums. |
StartRumblePulse(TBInput.Controller controller = TBInput.Controller.Active, RumblePulseStrength strength = RumblePulseStrength.Low, RumblePulseLength length = RumblePulseLength.Short) |
Fingers
Exposes hand presence data for animating virtual hands. Finger types include Thumb
, Index
, and Grip
.
Function | Description |
---|---|
float GetFinger(TBInput.Finger finger, TBInput.Controller controller) |
Returns float between 0 and 1.0 means the finger is up. 1 means the finger is down. |
bool SupportsFinger(TBInput.Finger finger, TBInput.Controller controller) |
Returns true if TButt has presence data for the specified finger on the specified controller. |
The float value returned by GetFinger()
differs slightly based on the hardware capabilities of the button that the player’s finger rests on:
Capability | Value |
---|---|
Touch | Returns 0.1 if button is being touched, but not pressed. |
Analog | Returns value between 0.1 and 1 if button is being pressed. |
Digital | Returns 1 if button is being pressed. |
All | Returns 0 if button is not being touched or pressed, or if presence data is not available for the specified finger. |
The buttons used to drive finger data on each supported controller are listed below:
Controller | Thumb | Index | Grip |
---|---|---|---|
Oculus Go Controller | Touchpad | Trigger | |
Oculus Touch (Rift) | A/X Thumbstick |
Index Trigger | Hand Trigger |
Oculus Touch (Quest) | A/X Thumbstick |
Index Trigger | Hand Trigger |
Vive Controller | Touchpad | Trigger | |
Windows Mixed Reality | Touchpad | Index Trigger | Hand Trigger |
Note: For controllers where more than one button can drive a finger, all buttons are checked and the largest returned value (from 0 to 1) is used.
Events
You can interface with TBInput
using events instead of checking button states in an update loop, if you prefer. Enable events in the Input Settings menu, and subscribe to them through TBInput.Events
.
Note: Events will be forced on if your game supports 3DOF controllers so handedness changes can be detected.
System Events
Event | Description |
---|---|
OnControlTypeChanged(TBInput.ControlType type) |
Fires when the active ControlType is changed. |
OnHandednessChanged(TBInput.Mobile3DOFHandedness handedness) |
Fires when the player’s handedness preference is changed on 3DOF controllers. |
Button Events
If enabled in the Input Settings menu, button events can be subscribed to through TBInput.Events.Button
.
Touch Events
If enabled in the Input Settings menu, touch events can be subscribed to through TBInput.Events.Touch
.