Class XRInteractableAffordanceStateProvider
State Machine component that derives an interaction affordance state from an associated IXRInteractable.
Inheritance
Inherited Members
Namespace: UnityEngine.XR.Interaction.Toolkit.AffordanceSystem.State
Assembly: Unity.XR.Interaction.Toolkit.dll
Syntax
[AddComponentMenu("Affordance System/XR Interactable Affordance State Provider", 11)]
[HelpURL("https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@2.5/api/UnityEngine.XR.Interaction.Toolkit.AffordanceSystem.State.XRInteractableAffordanceStateProvider.html")]
[DisallowMultipleComponent]
public class XRInteractableAffordanceStateProvider : BaseAffordanceStateProvider
Properties
activateClickAnimationMode
Condition to trigger click animation for activated interaction events.
Declaration
public XRInteractableAffordanceStateProvider.ActivateClickAnimationMode activateClickAnimationMode { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableAffordanceStateProvider.ActivateClickAnimationMode |
See Also
clickAnimationCurve
Animation curve reference for click animation events.
Declaration
public AnimationCurveDatumProperty clickAnimationCurve { get; set; }
Property Value
Type | Description |
---|---|
AnimationCurveDatumProperty |
clickAnimationDuration
Duration of click animations for selected and activated events.
Declaration
public float clickAnimationDuration { get; set; }
Property Value
Type | Description |
---|---|
float |
ignoreActivateEvents
When activate events are registered and this is true, the state will fallback to idle or disabled.
Declaration
public bool ignoreActivateEvents { get; set; }
Property Value
Type | Description |
---|---|
bool |
ignoreFocusEvents
When focus events are registered and this is true, the state will fallback to idle or disabled.
Declaration
public bool ignoreFocusEvents { get; set; }
Property Value
Type | Description |
---|---|
bool |
ignoreHoverEvents
When hover events are registered and this is true, the state will fallback to idle or disabled.
Declaration
public bool ignoreHoverEvents { get; set; }
Property Value
Type | Description |
---|---|
bool |
ignoreHoverPriorityEvents
When hover events are registered and this is true, the state will fallback to hover. When this is false, this provider will check if the Interactable Source has priority for selection when hovered, and update its state accordingly.
Declaration
public bool ignoreHoverPriorityEvents { get; set; }
Property Value
Type | Description |
---|---|
bool |
Remarks
When updating this value to false during runtime, previously hover events are ignored.
ignoreSelectEvents
When select events are registered and this is true, the state will fallback to idle or disabled.
Declaration
public bool ignoreSelectEvents { get; set; }
Property Value
Type | Description |
---|---|
bool |
interactableSource
The interactable component that drives the affordance states. If null, Unity will try and find an interactable component attached.
Declaration
public Object interactableSource { get; set; }
Property Value
Type | Description |
---|---|
Object |
isActivated
Is attached interactable in an activated state.
Declaration
protected virtual bool isActivated { get; }
Property Value
Type | Description |
---|---|
bool |
isFocused
Is attached interactable in a focused state.
Declaration
protected virtual bool isFocused { get; }
Property Value
Type | Description |
---|---|
bool |
isHovered
Is attached interactable in a hovered state.
Declaration
protected virtual bool isHovered { get; }
Property Value
Type | Description |
---|---|
bool |
isRegistered
Is attached interactable in a registered state.
Declaration
protected virtual bool isRegistered { get; }
Property Value
Type | Description |
---|---|
bool |
isSelected
Is attached interactable in a selected state.
Declaration
protected virtual bool isSelected { get; }
Property Value
Type | Description |
---|---|
bool |
selectClickAnimationMode
Condition to trigger click animation for Selected interaction events.
Declaration
public XRInteractableAffordanceStateProvider.SelectClickAnimationMode selectClickAnimationMode { get; set; }
Property Value
Type | Description |
---|---|
XRInteractableAffordanceStateProvider.SelectClickAnimationMode |
See Also
Methods
ActivatedClickBehavior()
Handles starting the activated click animation coroutine. Stops any previously started coroutine.
Declaration
protected virtual void ActivatedClickBehavior()
Awake()
See MonoBehaviour.
Declaration
protected void Awake()
BindToProviders()
Inform all registered receivers of the current affordance state data and subscribe to changes of the affordance state.
Declaration
protected override void BindToProviders()
Overrides
Remarks
This method is automatically called by Unity when this component is enabled.
See Also
ClearBindings()
Triggers unbind action on all bindings and destroys all stored binding actions, as well as clears the group of all registered bindings.
Declaration
protected override void ClearBindings()
Overrides
Remarks
This method is automatically called by Unity when this component is disabled.
ClickAnimation(byte, float, Action)
Click animation coroutine that plays over a set period of time, transitioning between the lower and upper bounds of a given affordance state.
Declaration
protected virtual IEnumerator ClickAnimation(byte targetStateIndex, float duration, Action onComplete = null)
Parameters
Type | Name | Description |
---|---|---|
byte | targetStateIndex | Target animation state with bounds which to transition between. |
float | duration | Duration of the animation. |
Action | onComplete | OnComplete callback action. |
Returns
Type | Description |
---|---|
IEnumerator | Enumerator used to play as a coroutine. |
GenerateNewAffordanceState()
Evaluates the state of the current interactable to generate a corresponding AffordanceStateData.
Declaration
protected virtual AffordanceStateData GenerateNewAffordanceState()
Returns
Type | Description |
---|---|
AffordanceStateData | Newly generated affordance state corresponding to the interactable state. |
OnActivatedEvent(ActivateEventArgs)
Callback triggered by IXRActivateInteractable when the interactor triggers an activated event on the interactable. Refreshes the affordance state and triggers the ActivatedClickBehavior() animation coroutine if the activated animation mode is set to Activated.
Declaration
protected virtual void OnActivatedEvent(ActivateEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
ActivateEventArgs | args | ActivateEventArgs callback args. |
See Also
OnDeactivatedEvent(DeactivateEventArgs)
Callback triggered by IXRActivateInteractable when the interactor triggers an deactivated event on the interactable. Refreshes the affordance state and triggers the ActivatedClickBehavior() animation coroutine if the activated animation mode is set to deactivated.
Declaration
protected virtual void OnDeactivatedEvent(DeactivateEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
DeactivateEventArgs | args | DeactivateEventArgs callback args. |
See Also
OnFirstFocusEntered(FocusEnterEventArgs)
Callback triggered by IXRFocusInteractable when the first interactor gains focus of this interactable. Refreshes the affordance state
Declaration
protected virtual void OnFirstFocusEntered(FocusEnterEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
FocusEnterEventArgs | args | FocusEnterEventArgs callback args. |
See Also
OnFirstHoverEntered(HoverEnterEventArgs)
Callback triggered by IXRHoverInteractable when the first interactor begins hovering over this interactable. Refreshes the affordance state.
Declaration
protected virtual void OnFirstHoverEntered(HoverEnterEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
HoverEnterEventArgs | args | HoverEnterEventArgs callback args. |
See Also
OnFirstSelectEntered(SelectEnterEventArgs)
Callback triggered by IXRSelectInteractor when the first interactor begins selecting over this interactable. Refreshes the affordance state and triggers the SelectedClickBehavior() animation coroutine if the select animation mode is set to SelectEntered.
Declaration
protected virtual void OnFirstSelectEntered(SelectEnterEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
SelectEnterEventArgs | args | SelectEnterEventArgs callback args. |
See Also
OnHoverEntered(HoverEnterEventArgs)
Callback triggered by IXRHoverInteractable when an interactor begins hovering over this interactable. Refreshes the affordance state.
Declaration
protected virtual void OnHoverEntered(HoverEnterEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
HoverEnterEventArgs | args | HoverEnterEventArgs callback args. |
See Also
OnHoverExited(HoverExitEventArgs)
Callback triggered by IXRHoverInteractable when an interactor exits hovering over this interactable. Refreshes the affordance state.
Declaration
protected virtual void OnHoverExited(HoverExitEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
HoverExitEventArgs | args | HoverExitEventArgs callback args. |
See Also
OnLargestInteractionStrengthChanged(float)
Callback triggered by IXRInteractionStrengthInteractable when the largest interaction strength of the interactable changes. Refreshes the affordance state.
Declaration
protected virtual void OnLargestInteractionStrengthChanged(float value)
Parameters
Type | Name | Description |
---|---|---|
float | value | The new largest interaction strength value of all interactors hovering or selecting the interactable. |
OnLastFocusExited(FocusExitEventArgs)
Callback triggered by IXRFocusInteractable when the last interactor loses focus of this interactable. Refreshes the affordance state
Declaration
protected virtual void OnLastFocusExited(FocusExitEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
FocusExitEventArgs | args | FocusExitEventArgs callback args. |
See Also
OnLastHoverExited(HoverExitEventArgs)
Callback triggered by IXRHoverInteractable when the last interactor exits hovering over this interactable. Refreshes the affordance state.
Declaration
protected virtual void OnLastHoverExited(HoverExitEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
HoverExitEventArgs | args | HoverExitEventArgs callback args. |
See Also
OnLastSelectExited(SelectExitEventArgs)
Callback triggered by IXRSelectInteractor when the last interactor exits selecting over this interactable. Refreshes the affordance state and triggers the SelectedClickBehavior() animation coroutine if the select animation mode is set to SelectExited.
Declaration
protected virtual void OnLastSelectExited(SelectExitEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
SelectExitEventArgs | args | SelectExitEventArgs callback args. |
See Also
OnRegistered(InteractableRegisteredEventArgs)
Callback triggered when the interactable is registered with the XRInteractionManager. Sets the internal isRegistered flag to true and refreshes the affordance state.
Declaration
protected virtual void OnRegistered(InteractableRegisteredEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
InteractableRegisteredEventArgs | args | InteractableRegisteredEventArgs callback args. |
OnUnregistered(InteractableUnregisteredEventArgs)
Callback triggered when the interactable is unregistered with the XRInteractionManager. Sets the internal isRegistered flag to false and refreshes the affordance state.
Declaration
protected virtual void OnUnregistered(InteractableUnregisteredEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
InteractableUnregisteredEventArgs | args | InteractableUnregisteredEventArgs callback args. |
OnValidate()
See MonoBehaviour.
Declaration
protected override void OnValidate()
Overrides
RefreshState()
Re-evaluates the current affordance state and triggers events for receivers if it changed.
Declaration
public void RefreshState()
SelectedClickBehavior()
Handles starting the selected click animation coroutine. Stops any previously started coroutine.
Declaration
protected virtual void SelectedClickBehavior()
SetBoundInteractionReceiver(IXRInteractable)
Bind affordance provider state to IXRInteractable state and events.
Declaration
public bool SetBoundInteractionReceiver(IXRInteractable receiver)
Parameters
Type | Name | Description |
---|---|---|
IXRInteractable | receiver | Receiver to bind events from. |
Returns
Type | Description |
---|---|
bool | Whether binding was successful. |