Class XRBaseController
Interprets feature values on a tracked input controller device into XR Interaction states, such as Select. Additionally, it applies the current pose value of a tracked device to the transform of the GameObject.
Namespace: UnityEngine.XR.Interaction.Toolkit
Syntax
public abstract class XRBaseController : MonoBehaviour
Properties
activateInteractionState
(Read Only) The current activate interaction state.
Declaration
public InteractionState activateInteractionState { get; }
Property Value
Type | Description |
---|---|
InteractionState |
anchorControlDeadzone
Defines the deadzone values for device-based input when performing translate or rotate anchor actions.
Declaration
public float anchorControlDeadzone { get; set; }
Property Value
Type | Description |
---|---|
Single |
See Also
anchorControlOffAxisDeadzone
Defines the off-axis deadzone values for device-based input when performing translate or rotate anchor actions.
Declaration
public float anchorControlOffAxisDeadzone { get; set; }
Property Value
Type | Description |
---|---|
Single |
animateModel
Whether to animate the model in response to interaction events. When enabled, activates a named animation trigger upon selecting or deselecting.
Declaration
public bool animateModel { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
See Also
enableInputActions
Whether input for XR Interaction events is enabled for this controller. When enabled, the current input of the controller device will be read each frame.
Declaration
public bool enableInputActions { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
This can be disabled in order to drive the controller state manually instead of from reading current inputs, such as when playing back recorded inputs.
See Also
enableInputTracking
Whether input pose tracking is enabled for this controller. When enabled, the current tracking pose input of the controller device will be read each frame.
Declaration
public bool enableInputTracking { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
This can be disabled in order to drive the controller state manually instead of from reading current inputs, such as when playing back recorded pose inputs.
See Also
hideControllerModel
Whether the controller model should be hidden.
Declaration
public bool hideControllerModel { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
See Also
model
The instance of the controller model in the scene. This can be set to an existing object instead of using modelPrefab.
Declaration
public Transform model { get; set; }
Property Value
Type | Description |
---|---|
Transform |
Remarks
If set, it should reference a child GameObject of this behavior so it will update with the controller pose.
modelDeSelectTransition
The animation trigger name to activate upon deselecting.
Declaration
public string modelDeSelectTransition { get; set; }
Property Value
Type | Description |
---|---|
String |
modelParent
The transform that is used as the parent for the model prefab when it is instantiated.
Declaration
public Transform modelParent { get; set; }
Property Value
Type | Description |
---|---|
Transform |
Remarks
Automatically instantiated and set in Awake() if not already set. Setting this will not automatically destroy the previous object.
modelPrefab
The prefab of a controller model to show for this controller that will be automatically instantiated by this behavior.
Declaration
public Transform modelPrefab { get; set; }
Property Value
Type | Description |
---|---|
Transform |
Remarks
This behavior will automatically instantiate an instance of the prefab as a child of modelParent upon startup unless model is already set, in which case this value ignored.
See Also
modelSelectTransition
The animation trigger name to activate upon selecting.
Declaration
public string modelSelectTransition { get; set; }
Property Value
Type | Description |
---|---|
String |
modelTransform
The transform that is used as the parent for the model prefab when it is instantiated.
Declaration
public Transform modelTransform { get; set; }
Property Value
Type | Description |
---|---|
Transform |
Remarks
Automatically instantiated and set in Awake() if not already set. Setting this will not automatically destroy the previous object.
selectInteractionState
(Read Only) The current select interaction state.
Declaration
public InteractionState selectInteractionState { get; }
Property Value
Type | Description |
---|---|
InteractionState |
uiPressInteractionState
(Read Only) The current ui press interaction state.
Declaration
public InteractionState uiPressInteractionState { get; }
Property Value
Type | Description |
---|---|
InteractionState |
updateTrackingType
The time within the frame that the controller will sample tracking input.
Declaration
public XRBaseController.UpdateType updateTrackingType { get; set; }
Property Value
Type | Description |
---|---|
XRBaseController.UpdateType |
See Also
Methods
ApplyControllerState(XRInteractionUpdateOrder.UpdatePhase, XRControllerState)
Applies the given controller state to this XRBaseController. Depending on the update phase, the XR Interaction states may be copied and/or the pose value may be applied to the transform of the GameObject.
Declaration
protected virtual void ApplyControllerState(XRInteractionUpdateOrder.UpdatePhase updatePhase, XRControllerState controllerState)
Parameters
Type | Name | Description |
---|---|---|
XRInteractionUpdateOrder.UpdatePhase | updatePhase | The update phase this is called during. |
XRControllerState | controllerState | The state of the controller to apply. |
Awake()
See
Declaration
protected virtual void Awake()
GetControllerState(out XRControllerState)
Gets the state of the controller.
Declaration
public virtual bool GetControllerState(out XRControllerState controllerState)
Parameters
Type | Name | Description |
---|---|---|
XRControllerState | controllerState | When this method returns, contains the XRControllerState object representing the state of the controller. |
Returns
Type | Description |
---|---|
Boolean | Returns false. |
GetModelPrefab()
Gets the prefab that should be instantiated upon startup.
Declaration
protected virtual GameObject GetModelPrefab()
Returns
Type | Description |
---|---|
GameObject | Returns the prefab that should be instantiated upon startup. |
OnBeforeRender()
This method is automatically called for "Just Before Render" input updates for VR devices.
Declaration
protected virtual void OnBeforeRender()
OnDisable()
See
Declaration
protected virtual void OnDisable()
OnEnable()
See
Declaration
protected virtual void OnEnable()
SendHapticImpulse(Single, Single)
Play a haptic impulse on the controller if one is available.
Declaration
public virtual bool SendHapticImpulse(float amplitude, float duration)
Parameters
Type | Name | Description |
---|---|---|
Single | amplitude | Amplitude (from 0.0 to 1.0) to play impulse at. |
Single | duration | Duration (in seconds) to play haptic impulse. |
Returns
Type | Description |
---|---|
Boolean |
SetControllerState(XRControllerState)
Sets the state of the controller.
Declaration
public virtual void SetControllerState(XRControllerState controllerState)
Parameters
Type | Name | Description |
---|---|---|
XRControllerState | controllerState | The state of the controller to set. |
Update()
See
Declaration
protected void Update()
UpdateController()
Updates the controller every frame.
Declaration
protected virtual void UpdateController()
UpdateControllerModelAnimation()
Updates the animation on the model instance (if the model contains an
Declaration
protected virtual void UpdateControllerModelAnimation()
See Also
UpdateInput(XRControllerState)
Updates the XR Interaction states in the given controller state based on the current inputs of the controller device.
Declaration
protected virtual void UpdateInput(XRControllerState controllerState)
Parameters
Type | Name | Description |
---|---|---|
XRControllerState | controllerState | The state of the controller. |
UpdateTrackingInput(XRControllerState)
Updates the pose values in the given controller state based on the current tracking input of the controller device.
Declaration
protected virtual void UpdateTrackingInput(XRControllerState controllerState)
Parameters
Type | Name | Description |
---|---|---|
XRControllerState | controllerState | The state of the controller. |