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
Assembly: Unity.XR.Interaction.Toolkit.dll
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 |
See Also
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 |
---|---|
bool |
See Also
currentControllerState
The current state of the controller.
Declaration
public XRControllerState currentControllerState { get; set; }
Property Value
Type | Description |
---|---|
XRControllerState |
See Also
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 |
---|---|
bool |
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 |
---|---|
bool |
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 |
---|---|
bool |
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.
See Also
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.
See Also
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 |
See Also
uiPressInteractionState
(Read Only) The current UI press interaction state.
Declaration
public InteractionState uiPressInteractionState { get; }
Property Value
Type | Description |
---|---|
InteractionState |
See Also
uiScrollValue
(Read Only) The current UI scroll value.
Declaration
public Vector2 uiScrollValue { get; }
Property Value
Type | Description |
---|---|
Vector2 |
See Also
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(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. |
See Also
Awake()
See MonoBehaviour.
Declaration
protected virtual void Awake()
See Also
FixedUpdate()
Corresponds to FixedUpdate(). It has the frequency of the physics system and is called every fixed framerate frame.
Declaration
protected virtual void FixedUpdate()
See Also
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. |
See Also
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()
See Also
OnEnable()
See MonoBehaviour.
Declaration
protected virtual void OnEnable()
See Also
SendHapticImpulse(float, float)
Play a haptic impulse on the controller if one is available.
Declaration
public virtual bool SendHapticImpulse(float amplitude, float duration)
Parameters
Type | Name | Description |
---|---|---|
float | amplitude | Amplitude (from 0.0 to 1.0) to play impulse at. |
float | duration | Duration (in seconds) to play haptic impulse. |
Returns
Type | Description |
---|---|
bool |
See Also
Update()
See MonoBehaviour.
Declaration
protected void Update()
See Also
UpdateController()
Updates the controller every frame. This is called automatically from Update().
Declaration
protected virtual void UpdateController()
See Also
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. |
See Also
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. |