Class Interactable
Uses input and action data to declare a set of states
Maintains a collection of themes that react to state changes and provide sensory feedback
Passes state information and input data on to receivers that detect patterns and does stuff.
Implements
IMixedRealityFocusChangedHandler
IMixedRealityFocusHandler
IMixedRealityInputHandler
IMixedRealitySpeechHandler
IMixedRealityTouchHandler
IMixedRealityInputHandler<Vector2>
IMixedRealityInputHandler<Vector3>
IMixedRealityInputHandler<MixedRealityPose>
Assembly: cs.temp.dll.dll
[Serializable]
public class Interactable : MonoBehaviour, IMixedRealityFocusChangedHandler, IMixedRealityFocusHandler, IMixedRealityInputHandler, IMixedRealitySpeechHandler, IMixedRealityTouchHandler, IMixedRealityInputHandler<Vector2>, IMixedRealityInputHandler<Vector3>, IMixedRealityInputHandler<MixedRealityPose>
Fields
Can the user deselect a toggle?
A radial button or tab should set this to false
Declaration
Field Value
Is the interactive selectable?
When a multi-dimension button, can the user initiate switching dimensions?
Declaration
Field Value
A click must occur within this many seconds after an input down
Declaration
protected float clickTime
Field Value
Declaration
protected Coroutine clickValidTimer
Field Value
Type |
Description |
Coroutine |
|
Declaration
protected int dimensionIndex
Field Value
A way of adding more layers of states for controls like toggles.
This is capitalized and doesn't match conventions for backwards compatibility
(to not break people using Interactable). We tried using FormerlySerializedAs("Dimensions)
and renaming to "dimensions", however Unity did not properly pick up the former serialization,
so we maintained the old value. See https://github.com/microsoft/MixedRealityToolkit-Unity/issues/6169
Declaration
Field Value
The position of the controller when input down occurs.
Used to determine when controller has moved far enough to trigger gesture
Declaration
protected Vector3? dragStartPosition
Field Value
Declaration
protected readonly List<IMixedRealityPointer> focusingPointers
Field Value
Type |
Description |
List<IMixedRealityPointer> |
|
Declaration
protected bool forceUpdate
Field Value
Amount of time to "simulate" press states for interactions that do not utilize input up/down such as voice command
This allows for visual feedbacks and other typical UX responsiveness and behavior to occur
Declaration
protected const float globalFeedbackClickTime = 0.3F
Field Value
Declaration
protected Coroutine globalTimer
Field Value
Type |
Description |
Coroutine |
|
Declaration
protected List<IInteractableHandler> handlers
Field Value
Declaration
Field Value
Declaration
protected State lastState
Field Value
Declaration
public UnityEvent OnClick
Field Value
Type |
Description |
UnityEvent |
|
Declaration
protected readonly HashSet<IMixedRealityInputSource> pressingInputSources
Field Value
Type |
Description |
HashSet<IMixedRealityInputSource> |
|
Declaration
protected float rollOffTimer
Field Value
This string keyword is the voice command that will fire a click on this Interactable.
Declaration
public string VoiceCommand
Field Value
Declaration
public bool voiceRequiresFocus
Field Value
Properties
The list of running theme instances to receive state changes
When the dimension index changes, activeThemes updates to those assigned to that dimension.
Declaration
public IReadOnlyList<InteractableThemeBase> ActiveThemes { get; }
Property Value
Returns the current selection mode of the Interactable based on the number of Dimensions available
Declaration
public SelectionModes ButtonMode { get; }
Property Value
How many times this interactable was clicked
Declaration
public int ClickCount { get; }
Property Value
Current Dimension index based zero and must be less than Dimensions
Declaration
public int CurrentDimension { get; set; }
Property Value
Is the interactable enabled?
Declaration
[Obsolete("Use IsEnabled instead")]
public bool Enabled { get; set; }
Property Value
Does this interactable require focus
Declaration
[Obsolete("Use IsGlobal instead")]
public bool FocusEnabled { get; set; }
Property Value
Pointers that are focusing the interactable
Declaration
public List<IMixedRealityPointer> FocusingPointers { get; }
Property Value
Type |
Description |
List<IMixedRealityPointer> |
|
State that corresponds to Interactable is touching another object
Declaration
public virtual bool HasCollision { get; set; }
Property Value
State that corresponds to miscellaneous/custom use by consumers
Currently not controlled by Interactable directly
Declaration
public virtual bool HasCustom { get; set; }
Property Value
Declaration
public virtual bool HasFocus { get; set; }
Property Value
Currently pressed and some movement has occurred
Declaration
public virtual bool HasGesture { get; set; }
Property Value
State that corresponds to Gesture reaching max threshold or limits
Declaration
public virtual bool HasGestureMax { get; set; }
Property Value
A near interaction grabbable is actively being grabbed
Declaration
public virtual bool HasGrab { get; set; }
Property Value
State that corresponds to no focus,and finger is down.
Currently not controlled by Interactable directly
Declaration
public virtual bool HasObservation { get; set; }
Property Value
State that corresponds to has focus,and finger down.
Currently not controlled by Interactable directly
Declaration
public virtual bool HasObservationTargeted { get; set; }
Property Value
A near interaction touchable is actively being touched
Declaration
public virtual bool HasPhysicalTouch { get; set; }
Property Value
Declaration
public virtual bool HasPress { get; set; }
Property Value
A voice command has just occurred
Declaration
public virtual bool HasVoiceCommand { get; set; }
Property Value
The Interactable will only respond to input down events fired with the corresponding assigned Input Action.
Available input actions are populated via the Input Actions Profile under the MRTK Input System Profile assigned in the current scene
Declaration
public MixedRealityInputAction InputAction { get; set; }
Property Value
Type |
Description |
MixedRealityInputAction |
|
List of events added to this interactable
Declaration
public List<InteractableEvent> InteractableEvents { get; set; }
Property Value
Declaration
[Obsolete("Use IsEnabled instead")]
public bool IsDisabled { get; set; }
Property Value
Defines whether the Interactable is enabled or not internally
This is different than the Enabled property at the GameObject/Component level
When false, Interactable will continue to run in Unity but not respond to Input.
Declaration
public virtual bool IsEnabled { get; set; }
Property Value
If true, this Interactable will listen globally for any IMixedRealityInputHandler input events. These include general input up/down and clicks.
If false, this Interactable will only respond to general input click events if the pointer target is this GameObject's, or one of its children's, collider.
Declaration
public bool IsGlobal { get; set; }
Property Value
State that corresponds to no focus,and finger is up.
Currently not controlled by Interactable directly
Declaration
public virtual bool IsInteractive { get; set; }
Property Value
Targeted means the item has focus and finger is up
Currently not controlled by Interactable directly
Declaration
public virtual bool IsTargeted { get; set; }
Property Value
True if Selection is "Toggle" (Dimensions == 2)
Declaration
[Obsolete("Use ButtonMode to test if equal to SelectionModes.Toggle instead")]
public bool IsToggleButton { get; }
Property Value
Determines whether Interactable is toggled or not. If true, CurrentDimension should be 1 and if false, CurrentDimension should be 0
Declaration
public virtual bool IsToggled { get; set; }
Property Value
The Interactable has been clicked
Declaration
public virtual bool IsVisited { get; set; }
Property Value
A way of adding more layers of states for controls like toggles
Declaration
public int NumOfDimensions { get; set; }
Property Value
Input sources that are pressing the interactable
Declaration
public HashSet<IMixedRealityInputSource> PressingInputSources { get; }
Property Value
Type |
Description |
HashSet<IMixedRealityInputSource> |
|
List of profile configurations that match Visual Themes with GameObjects targets
Setting at runtime will re-create the runtime Theme Engines (i.e ActiveThemes property) being used by this class
Declaration
public List<InteractableProfileItem> Profiles { get; set; }
Property Value
Do voice commands require focus?
Declaration
[Obsolete("Use VoiceRequiresFocus instead")]
public bool RequiresFocus { get; set; }
Property Value
If true, when this component is destroyed, active themes will reset their modified properties to original values on the targeted GameObjects. If false, GameObject properties will remain as-is.
Declaration
public bool ResetOnDestroy { get; set; }
Property Value
Allows for switching colliders without firing a lose focus immediately for advanced controls like drop-downs
Declaration
public float RollOffTime { get; protected set; }
Property Value
The state logic class for storing and comparing states which determines the current value.
Declaration
public InteractableStates StateManager { get; protected set; }
Property Value
ScriptableObject to reference for basic state logic to follow when interacting and transitioning between states. Should generally be "DefaultInteractableStates" object
Declaration
public States States { get; set; }
Property Value
Does the voice command require this to have focus?
Registers as a global listener for speech commands, ignores input events
Declaration
public bool VoiceRequiresFocus { get; set; }
Property Value
Methods
Register OnClick extra handlers
Declaration
public void AddHandler(IInteractableHandler handler)
Parameters
Event receivers can be used to listen for different
events at runtime. This method allows receivers to be dynamically added at runtime.
Declaration
public T AddReceiver<T>()
where T : ReceiverBase, new()
Returns
Type |
Description |
T |
The new event receiver
|
Type Parameters
Declaration
protected virtual void Awake()
Based on button settings and state, should this button listen to input?
Declaration
protected virtual bool CanInteract()
Returns
Helper method to convert number of dimensions to the appropriate SelectionModes
Declaration
public static SelectionModes ConvertToSelectionMode(int dimensions)
Parameters
Type |
Name |
Description |
Int32 |
dimensions |
number of dimensions
|
Returns
Type |
Description |
SelectionModes |
SelectionModes for corresponding number of dimensions
|
Decreases the Current Dimension by 1. If at zero, then loop around to end (i.e Dimensions - 1)
Declaration
public void DecreaseDimension()
Force re-initialization of Interactable from events, themes and state references
Declaration
[Obsolete("Use RefreshSetup() instead")]
public void ForceUpdateThemes()
Creates the default States ScriptableObject configured for Interactable
Declaration
public static States GetDefaultInteractableStates()
Returns
Type |
Description |
States |
Default Interactable States asset
|
Helper function to create a new Theme asset using Default Interactable States and provided theme definitions
Declaration
public static Theme GetDefaultThemeAsset(List<ThemeDefinition> themeDefintions)
Parameters
Type |
Name |
Description |
List<ThemeDefinition> |
themeDefintions |
List of Theme Definitions to associate with Theme asset
|
Returns
Type |
Description |
Theme |
Theme ScriptableObject instance
|
A public way to access the current dimension
Declaration
[Obsolete("Use CurrentDimension property instead")]
public int GetDimensionIndex()
Returns
Returns the first receiver of type T on the interactable,
or null if nothing is found.
Declaration
public T GetReceiver<T>()
where T : ReceiverBase
Returns
Type Parameters
Returns all receivers of type T on the interactable.
If nothing is found, returns empty list.
Declaration
public List<T> GetReceivers<T>()
where T : ReceiverBase
Returns
Type Parameters
Returns a list of states assigned to the Interactable
Declaration
[Obsolete("Use States.StateList instead")]
public State[] GetStates()
Returns
Grabs the state value index, returns -1 if no StateManager available
Declaration
public int GetStateValue(InteractableStates.InteractableStateEnum state)
Parameters
Returns
Clears up any automated visual states
Declaration
protected IEnumerator GlobalVisualReset(float time)
Parameters
Type |
Name |
Description |
Single |
time |
|
Returns
Type |
Description |
IEnumerator |
|
Increases the Current Dimension by 1. If at end (i.e Dimensions - 1), then loop around to beginning (i.e 0)
Declaration
public void IncreaseDimension()
Declaration
protected virtual void Initialize()
A timer for the MixedRealityInputHandlers, clicks should occur within a certain time.
Declaration
protected IEnumerator InputDownTimer(float time)
Parameters
Type |
Name |
Description |
Single |
time |
|
Returns
Type |
Description |
IEnumerator |
|
Declaration
public void OnBeforeFocusChange(FocusEventData eventData)
Parameters
Type |
Name |
Description |
FocusEventData |
eventData |
|
Declaration
protected virtual void OnDestroy()
Declaration
protected virtual void OnDisable()
Declaration
protected virtual void OnEnable()
Declaration
public void OnFocusChanged(FocusEventData eventData)
Parameters
Type |
Name |
Description |
FocusEventData |
eventData |
|
Declaration
public void OnFocusEnter(FocusEventData eventData)
Parameters
Type |
Name |
Description |
FocusEventData |
eventData |
|
Declaration
public void OnFocusExit(FocusEventData eventData)
Parameters
Type |
Name |
Description |
FocusEventData |
eventData |
|
Declaration
public void OnInputChanged(InputEventData<MixedRealityPose> eventData)
Parameters
Type |
Name |
Description |
InputEventData<MixedRealityPose> |
eventData |
|
Declaration
public void OnInputChanged(InputEventData<Vector2> eventData)
Parameters
Type |
Name |
Description |
InputEventData<Vector2> |
eventData |
|
Declaration
public void OnInputChanged(InputEventData<Vector3> eventData)
Parameters
Type |
Name |
Description |
InputEventData<Vector3> |
eventData |
|
Declaration
public void OnInputDown(InputEventData eventData)
Parameters
Type |
Name |
Description |
InputEventData |
eventData |
|
Declaration
public void OnInputUp(InputEventData eventData)
Parameters
Type |
Name |
Description |
InputEventData |
eventData |
|
Declaration
public void OnPositionInputChanged(InputEventData<Vector2> eventData)
Parameters
Type |
Name |
Description |
InputEventData<Vector2> |
eventData |
|
Voice commands from MixedRealitySpeechCommandProfile, keyword recognized
Declaration
public void OnSpeechKeywordRecognized(SpeechEventData eventData)
Parameters
Type |
Name |
Description |
SpeechEventData |
eventData |
|
Declaration
public void OnTouchCompleted(HandTrackingInputEventData eventData)
Parameters
Type |
Name |
Description |
HandTrackingInputEventData |
eventData |
|
Declaration
public void OnTouchStarted(HandTrackingInputEventData eventData)
Parameters
Type |
Name |
Description |
HandTrackingInputEventData |
eventData |
|
Declaration
public void OnTouchUpdated(HandTrackingInputEventData eventData)
Parameters
Type |
Name |
Description |
HandTrackingInputEventData |
eventData |
|
Force re-initialization of Interactable from events, themes and state references
Declaration
public void RefreshSetup()
Declaration
public void RemoveHandler(IInteractableHandler handler)
Parameters
Reset all states in the Interactable and pointer information
Declaration
public void ResetAllStates()
Resets input tracking states such as focus or grab that are directly controlled by Interactable
Declaration
[Obsolete("Use ResetInputTrackingStates property instead")]
public void ResetBaseStates()
Reset the input tracking states directly managed by Interactable such as whether the component has focus or is being grabbed
Useful for when needing to reset input interactions
Declaration
public void ResetInputTrackingStates()
Assigns the InputAction based on the InputActionId
Declaration
public static MixedRealityInputAction ResolveInputAction(int index)
Parameters
Type |
Name |
Description |
Int32 |
index |
|
Returns
Type |
Description |
MixedRealityInputAction |
|
Call onClick methods on receivers or IInteractableHandlers
Declaration
protected void SendOnClick(IMixedRealityPointer pointer)
Parameters
Type |
Name |
Description |
IMixedRealityPointer |
pointer |
|
call OnVoinceCommand methods on receivers or IInteractableHandlers
Declaration
protected void SendVoiceCommands(string command, int index, int length)
Parameters
Change the collision state
Declaration
[Obsolete("Use HasCollision property instead")]
public virtual void SetCollision(bool collision)
Parameters
Type |
Name |
Description |
Boolean |
collision |
|
Declaration
[Obsolete("Use HasCustom property instead")]
public virtual void SetCustom(bool custom)
Parameters
Type |
Name |
Description |
Boolean |
custom |
|
a public way to set the dimension index
Declaration
[Obsolete("Use CurrentDimension property instead")]
public void SetDimensionIndex(int index)
Parameters
Type |
Name |
Description |
Int32 |
index |
|
Change the disabled state, will override the Enabled property
Declaration
[Obsolete("Use IsEnabled property instead")]
public virtual void SetDisabled(bool disabled)
Parameters
Type |
Name |
Description |
Boolean |
disabled |
|
Handle focus state changes
Declaration
[Obsolete("Use Focus property instead")]
public virtual void SetFocus(bool focus)
Parameters
Type |
Name |
Description |
Boolean |
focus |
|
Declaration
[Obsolete("Use HasGesture property instead")]
public virtual void SetGesture(bool gesture)
Parameters
Type |
Name |
Description |
Boolean |
gesture |
|
Change the gesture max state
Declaration
[Obsolete("Use HasGestureMax property instead")]
public virtual void SetGestureMax(bool gesture)
Parameters
Type |
Name |
Description |
Boolean |
gesture |
|
Declaration
[Obsolete("Use HasGrab property instead")]
public virtual void SetGrab(bool grab)
Parameters
Public method that can be used to set state of interactable
corresponding to an input going down (select button, menu button, touch)
Declaration
public void SetInputDown()
Public method that can be used to set state of interactable
corresponding to an input going up.
Declaration
Change the Interactive state
Declaration
[Obsolete("Use IsInteractive property instead")]
public virtual void SetInteractive(bool interactive)
Parameters
Type |
Name |
Description |
Boolean |
interactive |
|
Change the observation state
Declaration
[Obsolete("Use HasObservation property instead")]
public virtual void SetObservation(bool observation)
Parameters
Type |
Name |
Description |
Boolean |
observation |
|
Change the observation targeted state
Declaration
[Obsolete("Use HasObservationTargeted property instead")]
public virtual void SetObservationTargeted(bool targeted)
Parameters
Type |
Name |
Description |
Boolean |
targeted |
|
Change the physical touch state
Declaration
[Obsolete("Use HasPhysicalTouch property instead")]
public virtual void SetPhysicalTouch(bool touch)
Parameters
Type |
Name |
Description |
Boolean |
touch |
|
Declaration
[Obsolete("Use Press property instead")]
public virtual void SetPress(bool press)
Parameters
Type |
Name |
Description |
Boolean |
press |
|
a public way to set state directly
Declaration
public void SetState(InteractableStates.InteractableStateEnum state, bool value)
Parameters
Change the targeted state
Declaration
[Obsolete("Use IsTargeted property instead")]
public virtual void SetTargeted(bool targeted)
Parameters
Type |
Name |
Description |
Boolean |
targeted |
|
Declaration
[Obsolete("Use IsToggled property instead")]
public virtual void SetToggled(bool toggled)
Parameters
Type |
Name |
Description |
Boolean |
toggled |
|
Creates the event receiver instances from the Events list
Declaration
protected virtual void SetupEvents()
Declaration
protected virtual void SetupStates()
Declaration
[Obsolete("Use IsVisited property instead")]
public virtual void SetVisited(bool visited)
Parameters
Type |
Name |
Description |
Boolean |
visited |
|
Change the voice command state
Declaration
[Obsolete("Use HasVoiceCommand property instead")]
public virtual void SetVoiceCommand(bool voice)
Parameters
Type |
Name |
Description |
Boolean |
voice |
|
Based on inputAction and state, should interactable listen to this up/down event.
Declaration
protected virtual bool ShouldListenToUpDownEvent(InputEventData data)
Parameters
Type |
Name |
Description |
InputEventData |
data |
|
Returns
Declaration
protected virtual void Start()
Starts a timer to check if input is in progress
- Make sure global pointer events are not double firing
- Make sure Global Input events are not double firing
- Make sure pointer events are not duplicating an input event
Declaration
protected void StartClickTimer(bool isFromInputDown = false)
Parameters
Type |
Name |
Description |
Boolean |
isFromInputDown |
|
For input "clicks" that do not have corresponding input up/down tracking such as voice commands
Simulate pressed and start timer to reset states after some click time
Declaration
protected void StartGlobalVisual(bool voiceCommand = false)
Parameters
Type |
Name |
Description |
Boolean |
voiceCommand |
|
Declaration
protected void StopClickTimer()
A public way to trigger or route an onClick event from an external source, like PressableButton
Declaration
public void TriggerOnClick()
Declaration
protected virtual void Update()
Updates the list of active themes based the current dimensions index
Declaration
protected virtual void UpdateActiveThemes()
runs the state logic and sets state based on the current state values
Declaration
protected virtual void UpdateState()
Implements
IMixedRealityFocusChangedHandler
IMixedRealityFocusHandler
IMixedRealityInputHandler
IMixedRealitySpeechHandler
IMixedRealityTouchHandler
IMixedRealityInputHandler<>
IMixedRealityInputHandler<>
IMixedRealityInputHandler<>