Class XRDeviceSimulator
A component which handles mouse and keyboard input from the user and uses it to drive simulated XR controllers and an XR head mounted display (HMD).
Inherited Members
Namespace: UnityEngine.XR.Interaction.Toolkit.Inputs.Simulation
Syntax
[AddComponentMenu("XR/Debug/XR Device Simulator", 11)]
[DefaultExecutionOrder(-29991)]
[HelpURL("https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@2.0/api/UnityEngine.XR.Interaction.Toolkit.Inputs.Simulation.XRDeviceSimulator.html")]
public class XRDeviceSimulator : MonoBehaviour
Remarks
This class does not directly manipulate the camera or controllers which are part of
the XR Origin, but rather drives them indirectly through simulated input devices.
Use the Package Manager window to install the XR Device Simulator sample into
your project to get sample mouse and keyboard bindings for Input System actions that
this component expects. The sample also includes a prefab of a GameObject
with this component attached that has references to those sample actions already set.
To make use of this simulator, add the prefab to your scene (the prefab makes use
of InputActionManager to ensure the Input System actions are enabled).
Note that the XR Origin must read the position and rotation of the HMD and controllers
by using Input System actions (such as by using ActionBasedController
and TrackedPoseDriver) for this simulator to work as expected.
Attempting to use XR input subsystem device methods (such as by using XRController
and TrackedPoseDriver) will not work as expected
since this simulator depends on the Input System to drive the simulated devices.
Properties
axis2DAction
The Input System Action used to control the value of one or more 2D Axis controls on the manipulated controller device(s). Must be a Value Vector2Control.
Declaration
public InputActionReference axis2DAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
Remarks
togglePrimary2DAxisTargetAction and toggleSecondary2DAxisTargetAction toggle enables
the ability to manipulate 2D Axis controls on the simulated controllers, and this axis2DAction
actually controls the value of them while those controller devices are being manipulated.
Typically bound to WASD on a keyboard, and controls the primary and/or secondary 2D Axis controls on them.
axis2DTargets
One or more 2D Axis controls that keyboard input should apply to (or none).
Declaration
public XRDeviceSimulator.Axis2DTargets axis2DTargets { get; set; }
Property Value
Type | Description |
---|---|
XRDeviceSimulator.Axis2DTargets |
Remarks
Used to control a combination of the position (Position), primary 2D axis (Primary2DAxis), or secondary 2D axis (Secondary2DAxis) of manipulated device(s).
See Also
cameraTransform
The Transform that contains the Camera. This is usually the "Head" of XR Origins. Automatically set to main if unset.
Declaration
public Transform cameraTransform { get; set; }
Property Value
Type | Description |
---|---|
Transform |
desiredCursorLockMode
Declaration
public CursorLockMode desiredCursorLockMode { get; set; }
Property Value
Type | Description |
---|---|
CursorLockMode |
See Also
gripAction
The Input System Action used to control the Grip control of the manipulated controller device(s). Must be a ButtonControl.
Declaration
public InputActionReference gripAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
keyboardTranslateSpace
The coordinate space in which keyboard translation should operate.
Declaration
public XRDeviceSimulator.Space keyboardTranslateSpace { get; set; }
Property Value
Type | Description |
---|---|
XRDeviceSimulator.Space |
See Also
keyboardXTranslateAction
The Input System Action used to translate in the x-axis (left/right) while held. Must be a Value AxisControl.
Declaration
public InputActionReference keyboardXTranslateAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
keyboardXTranslateSpeed
Speed of translation in the x-axis (left/right) when triggered by keyboard input.
Declaration
public float keyboardXTranslateSpeed { get; set; }
Property Value
Type | Description |
---|---|
Single |
See Also
keyboardYTranslateAction
The Input System Action used to translate in the y-axis (up/down) while held. Must be a Value AxisControl.
Declaration
public InputActionReference keyboardYTranslateAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
keyboardYTranslateSpeed
Speed of translation in the y-axis (up/down) when triggered by keyboard input.
Declaration
public float keyboardYTranslateSpeed { get; set; }
Property Value
Type | Description |
---|---|
Single |
See Also
keyboardZTranslateAction
The Input System Action used to translate in the z-axis (forward/back) while held. Must be a Value AxisControl.
Declaration
public InputActionReference keyboardZTranslateAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
keyboardZTranslateSpeed
Speed of translation in the z-axis (forward/back) when triggered by keyboard input.
Declaration
public float keyboardZTranslateSpeed { get; set; }
Property Value
Type | Description |
---|---|
Single |
See Also
manipulateHeadAction
The Input System Action used to enable manipulation of the HMD while held. Must be a ButtonControl.
Declaration
public InputActionReference manipulateHeadAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
manipulateLeftAction
The Input System Action used to enable manipulation of the left-hand controller while held. Must be a ButtonControl.
Declaration
public InputActionReference manipulateLeftAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
Remarks
Note that if controls on the left-hand controller are actuated when this action is released, those controls will continue to remain actuated. This is to allow for multi-hand interactions without needing to have dedicated bindings for manipulating each controller separately and concurrently.
See Also
manipulateRightAction
The Input System Action used to enable manipulation of the right-hand controller while held. Must be a ButtonControl.
Declaration
public InputActionReference manipulateRightAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
Remarks
Note that if controls on the right-hand controller are actuated when this action is released, those controls will continue to remain actuated. This is to allow for multi-hand interactions without needing to have dedicated bindings for manipulating each controller separately and concurrently.
See Also
menuAction
The Input System Action used to control the Menu control of the manipulated controller device(s). Must be a ButtonControl.
Declaration
public InputActionReference menuAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
mouseDeltaAction
The Input System Action used to translate or rotate by a scaled amount along or about the x- and y-axes. Must be a Value Vector2Control.
Declaration
public InputActionReference mouseDeltaAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
Remarks
Typically bound to the screen-space motion delta of the mouse in pixels.
See Also
mouseScrollAction
The Input System Action used to translate or rotate by a scaled amount along or about the z-axis. Must be a Value Vector2Control.
Declaration
public InputActionReference mouseScrollAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
Remarks
Typically bound to the horizontal and vertical scroll wheels, though only the vertical is used.
See Also
mouseScrollRotateSensitivity
Sensitivity of rotation along the z-axis (roll) when triggered by mouse scroll input.
Declaration
public float mouseScrollRotateSensitivity { get; set; }
Property Value
Type | Description |
---|---|
Single |
See Also
mouseScrollTranslateSensitivity
Sensitivity of translation in the z-axis (forward/back) when triggered by mouse scroll input.
Declaration
public float mouseScrollTranslateSensitivity { get; set; }
Property Value
Type | Description |
---|---|
Single |
See Also
mouseTransformationMode
The transformation mode in which the mouse should operate.
Declaration
public XRDeviceSimulator.TransformationMode mouseTransformationMode { get; set; }
Property Value
Type | Description |
---|---|
XRDeviceSimulator.TransformationMode |
mouseTranslateSpace
The coordinate space in which mouse translation should operate.
Declaration
public XRDeviceSimulator.Space mouseTranslateSpace { get; set; }
Property Value
Type | Description |
---|---|
XRDeviceSimulator.Space |
See Also
mouseXRotateSensitivity
Sensitivity of rotation along the x-axis (pitch) when triggered by mouse input.
Declaration
public float mouseXRotateSensitivity { get; set; }
Property Value
Type | Description |
---|---|
Single |
See Also
mouseXTranslateSensitivity
Sensitivity of translation in the x-axis (left/right) when triggered by mouse input.
Declaration
public float mouseXTranslateSensitivity { get; set; }
Property Value
Type | Description |
---|---|
Single |
See Also
mouseYRotateInvert
A boolean value of whether to invert the y-axis of mouse input when rotating by mouse input. A false value (default) means typical FPS style where moving the mouse up/down pitches up/down. A true value means flight control style where moving the mouse up/down pitches down/up.
Declaration
public bool mouseYRotateInvert { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
mouseYRotateSensitivity
Sensitivity of rotation along the y-axis (yaw) when triggered by mouse input.
Declaration
public float mouseYRotateSensitivity { get; set; }
Property Value
Type | Description |
---|---|
Single |
See Also
mouseYTranslateSensitivity
Sensitivity of translation in the y-axis (up/down) when triggered by mouse input.
Declaration
public float mouseYTranslateSensitivity { get; set; }
Property Value
Type | Description |
---|---|
Single |
See Also
negateModeAction
The Input System Action used to cause the manipulated device(s) to rotate when moving the mouse while held when it would normally translate, and vice-versa. Must be a ButtonControl.
Declaration
public InputActionReference negateModeAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
Remarks
Can be used to temporarily change the mouse transformation mode to the other mode while held for making quick adjustments.
See Also
primary2DAxisClickAction
The Input System Action used to control the Primary2DAxisClick control of the manipulated controller device(s). Must be a ButtonControl.
Declaration
public InputActionReference primary2DAxisClickAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
primary2DAxisTouchAction
The Input System Action used to control the Primary2DAxisTouch control of the manipulated controller device(s). Must be a ButtonControl.
Declaration
public InputActionReference primary2DAxisTouchAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
primaryButtonAction
The Input System Action used to control the PrimaryButton control of the manipulated controller device(s). Must be a ButtonControl.
Declaration
public InputActionReference primaryButtonAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
primaryTouchAction
The Input System Action used to control the PrimaryTouch control of the manipulated controller device(s). Must be a ButtonControl.
Declaration
public InputActionReference primaryTouchAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
removeOtherHMDDevices
This boolean value indicates whether or not we remove other XRHMD devices in this session so that they don't conflict with the XRDeviceSimulator. A true value (default) means we remove all other XRHMD devices except the XRSimulatedHMD generated by the XRDeviceSimulator. A false value means we do not remove any other XRHMD devices.
Declaration
public bool removeOtherHMDDevices { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
resetAction
The Input System Action used to cause the manipulated device(s) to reset position or rotation (depending on the effective manipulation mode). Must be a ButtonControl.
Declaration
public InputActionReference resetAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
Remarks
Resets position to zero and rotation to identity. May be combined with axis constraints (xConstraintAction, yConstraintAction, and zConstraintAction).
restingHandAxis2DAction
The Input System Action used to control one or more 2D Axis controls on the opposite hand of the exclusively manipulated controller device. Must be a Value Vector2Control.
Declaration
public InputActionReference restingHandAxis2DAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
Remarks
Typically bound to Q and E on a keyboard for the horizontal component, and controls the opposite hand's 2D Axis controls when manipulating one (and only one) controller. Can be used to quickly and simultaneously control the 2D Axis on the other hand's controller. In a typical setup of continuous movement bound on the left-hand controller stick, and turning bound on the right-hand controller stick, while exclusively manipulating the left-hand controller to move, this action can be used to trigger turning.
See Also
rotateModeOverrideAction
The Input System Action used to cause the manipulated device(s) to rotate when moving the mouse when held. Must be a ButtonControl.
Declaration
public InputActionReference rotateModeOverrideAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
Remarks
Forces rotation mode when held, no matter what the current mouse transformation mode is.
See Also
secondary2DAxisClickAction
The Input System Action used to control the Secondary2DAxisClick control of the manipulated controller device(s). Must be a ButtonControl.
Declaration
public InputActionReference secondary2DAxisClickAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
secondary2DAxisTouchAction
The Input System Action used to control the Secondary2DAxisTouch control of the manipulated controller device(s). Must be a ButtonControl.
Declaration
public InputActionReference secondary2DAxisTouchAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
secondaryButtonAction
The Input System Action used to control the SecondaryButton control of the manipulated controller device(s). Must be a ButtonControl.
Declaration
public InputActionReference secondaryButtonAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
secondaryTouchAction
The Input System Action used to control the SecondaryTouch control of the manipulated controller device(s). Must be a ButtonControl.
Declaration
public InputActionReference secondaryTouchAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
toggleCursorLockAction
The Input System Action used to toggle the cursor lock mode for the game window when pressed. Must be a ButtonControl.
Declaration
public InputActionReference toggleCursorLockAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
See Also
toggleDevicePositionTargetAction
The Input System Action used to toggle enable translation from keyboard inputs when pressed. Must be a ButtonControl.
Declaration
public InputActionReference toggleDevicePositionTargetAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
See Also
toggleManipulateLeftAction
The Input System Action used to toggle enable manipulation of the left-hand controller when pressed. Must be a ButtonControl.
Declaration
public InputActionReference toggleManipulateLeftAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
See Also
toggleManipulateRightAction
The Input System Action used to toggle enable manipulation of the right-hand controller when pressed. Must be a ButtonControl.
Declaration
public InputActionReference toggleManipulateRightAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
See Also
toggleMouseTransformationModeAction
The Input System Action used to toggle between translating or rotating the manipulated device(s) when moving the mouse when pressed. Must be a ButtonControl.
Declaration
public InputActionReference toggleMouseTransformationModeAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
togglePrimary2DAxisTargetAction
The Input System action used to toggle enable manipulation of the Primary2DAxis of the controllers when pressed. Must be a ButtonControl.
Declaration
public InputActionReference togglePrimary2DAxisTargetAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
See Also
toggleSecondary2DAxisTargetAction
The Input System action used to toggle enable manipulation of the Secondary2DAxis of the controllers when pressed. Must be a ButtonControl.
Declaration
public InputActionReference toggleSecondary2DAxisTargetAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
See Also
triggerAction
The Input System Action used to control the Trigger control of the manipulated controller device(s). Must be a ButtonControl.
Declaration
public InputActionReference triggerAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
xConstraintAction
The Input System Action used to constrain the translation or rotation to the x-axis when moving the mouse or resetting. May be combined with another axis constraint to constrain to a plane. Must be a ButtonControl.
Declaration
public InputActionReference xConstraintAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
See Also
yConstraintAction
The Input System Action used to constrain the translation or rotation to the y-axis when moving the mouse or resetting. May be combined with another axis constraint to constrain to a plane. Must be a ButtonControl.
Declaration
public InputActionReference yConstraintAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
See Also
zConstraintAction
The Input System Action used to constrain the translation or rotation to the z-axis when moving the mouse or resetting. May be combined with another axis constraint to constrain to a plane. Must be a ButtonControl.
Declaration
public InputActionReference zConstraintAction { get; set; }
Property Value
Type | Description |
---|---|
InputActionReference |
See Also
Methods
AddDevices()
Add simulated XR devices to the Input System.
Declaration
protected virtual void AddDevices()
Awake()
See MonoBehaviour.
Declaration
protected virtual void Awake()
GetResetScale()
Gets a Vector3 that can be multiplied component-wise with another Vector3 to reset components of the Vector3, based on axis constraint inputs.
Declaration
protected Vector3 GetResetScale()
Returns
Type | Description |
---|---|
Vector3 |
See Also
OnDisable()
See MonoBehaviour.
Declaration
protected virtual void OnDisable()
OnEnable()
See MonoBehaviour.
Declaration
protected virtual void OnEnable()
ProcessAxis2DControlInput()
Process input from the user and update the state of manipulated controller device(s) related to 2D Axis input controls.
Declaration
protected virtual void ProcessAxis2DControlInput()
ProcessButtonControlInput(ref XRSimulatedControllerState)
Process input from the user and update the state of manipulated controller device(s) related to button input controls.
Declaration
protected virtual void ProcessButtonControlInput(ref XRSimulatedControllerState controllerState)
Parameters
Type | Name | Description |
---|---|---|
XRSimulatedControllerState | controllerState | The controller state that will be processed. |
ProcessControlInput()
Process input from the user and update the state of manipulated controller device(s) related to input controls.
Declaration
protected virtual void ProcessControlInput()
ProcessPoseInput()
Process input from the user and update the state of manipulated device(s) related to position and rotation.
Declaration
protected virtual void ProcessPoseInput()
RemoveDevices()
Remove simulated XR devices from the Input System.
Declaration
protected virtual void RemoveDevices()
Update()
See MonoBehaviour.
Declaration
protected virtual void Update()