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.
Inherited Members
Namespace: UnityEngine.XR.Interaction.Toolkit
Syntax
[DefaultExecutionOrder(-29990)]
[DisallowMultipleComponent]
public abstract class XRBaseController : MonoBehaviour
Properties
activateInteractionState
(Read Only) The current activate interaction state.
Declaration
public InteractionState activateInteractionState { get; }
Property Value
Type | Description |
---|---|
InteractionState |
animateModel
Whether to animate the model in response to interaction events. When enabled, the animation trigger will be set for the corresponding animator component on the controller model when a select or deselect interaction events occurs.
Declaration
public bool animateModel { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
See Also
currentControllerState
The current state of the controller.
Declaration
public XRControllerState currentControllerState { get; set; }
Property Value
Type | Description |
---|---|
XRControllerState |
enableInputActions
Whether input for XR Interaction events is enabled for this controller. When enabled, Unity reads the current input of the controller device each frame.
Declaration
public bool enableInputActions { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
You can disable this 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, Unity reads the current tracking pose input of the controller device each frame.
Declaration
public bool enableInputTracking { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
You can disable this 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 to hide the controller model.
Declaration
public bool hideControllerModel { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
See Also
model
The instance of the controller model in the scene. You can set this 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 |
See Also
modelParent
The transform that this behavior uses 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 this behavior automatically instantiates.
Declaration
public Transform modelPrefab { get; set; }
Property Value
Type | Description |
---|---|
Transform |
Remarks
This behavior automatically instantiates an instance of the prefab as a child of modelParent upon startup unless model is already set, in which case this value is ignored.
See Also
modelSelectTransition
The animation trigger name to activate upon selecting.
Declaration
public string modelSelectTransition { get; set; }
Property Value
Type | Description |
---|---|
String |
See Also
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 |
uiScrollValue
(Read Only) The current UI scroll value.
Declaration
public Vector2 uiScrollValue { get; }
Property Value
Type | Description |
---|---|
Vector2 |
updateTrackingType
The time within the frame that the controller samples 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. Unity calls this automatically from FixedUpdate(), OnBeforeRender(), and UpdateController().
Declaration
protected virtual void ApplyControllerState(XRInteractionUpdateOrder.UpdatePhase updatePhase, XRControllerState controllerState)
Parameters
Type | Name | Description |
---|---|---|
XRInteractionUpdateOrder.UpdatePhase | updatePhase | The update phase during this call. |
XRControllerState | controllerState | The state of the controller to apply. |
Awake()
See MonoBehaviour.
Declaration
protected virtual void Awake()
FixedUpdate()
Corresponds to FixedUpdate(). It has the frequency of the physics system and is called every fixed framerate frame.
Declaration
protected virtual void FixedUpdate()
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()
See Also
OnDisable()
See MonoBehaviour.
Declaration
protected virtual void OnDisable()
OnEnable()
See MonoBehaviour.
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 |
Update()
See MonoBehaviour.
Declaration
protected void Update()
UpdateController()
Updates the controller every frame. This is called automatically from Update().
Declaration
protected virtual void UpdateController()
UpdateControllerModelAnimation()
Updates the animation on the model instance (if the model contains an Animator). Unity calls this automatically from UpdateController().
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. Unity calls this automatically during UpdateController() so explicit calls to this function are not required.
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. Unity calls this automatically from FixedUpdate(), OnBeforeRender(), and UpdateController() so explicit calls to this function are not required.
Declaration
protected virtual void UpdateTrackingInput(XRControllerState controllerState)
Parameters
Type | Name | Description |
---|---|---|
XRControllerState | controllerState | The state of the controller. |