Bearbeiten

Freigeben über


Interactable Class

Definition

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.

public ref class Interactable : UnityEngine::MonoBehaviour, Microsoft::MixedReality::Toolkit::Input::IMixedRealityFocusChangedHandler, Microsoft::MixedReality::Toolkit::Input::IMixedRealityFocusHandler, Microsoft::MixedReality::Toolkit::Input::IMixedRealityInputHandler, Microsoft::MixedReality::Toolkit::Input::IMixedRealityInputHandler<Microsoft::MixedReality::Toolkit::Utilities::MixedRealityPose>, Microsoft::MixedReality::Toolkit::Input::IMixedRealityInputHandler<UnityEngine::Vector2>, Microsoft::MixedReality::Toolkit::Input::IMixedRealityInputHandler<UnityEngine::Vector3>, Microsoft::MixedReality::Toolkit::Input::IMixedRealitySpeechHandler, Microsoft::MixedReality::Toolkit::Input::IMixedRealityTouchHandler, UnityEngine::EventSystems::IEventSystemHandler
[UnityEngine.AddComponentMenu("Scripts/MRTK/SDK/Interactable")]
[UnityEngine.HelpURL("https://docs.microsoft.com/windows/mixed-reality/mrtk-unity/features/ux-building-blocks/interactable")]
[System.Serializable]
public class Interactable : UnityEngine.MonoBehaviour, Microsoft.MixedReality.Toolkit.Input.IMixedRealityFocusChangedHandler, Microsoft.MixedReality.Toolkit.Input.IMixedRealityFocusHandler, Microsoft.MixedReality.Toolkit.Input.IMixedRealityInputHandler, Microsoft.MixedReality.Toolkit.Input.IMixedRealityInputHandler<Microsoft.MixedReality.Toolkit.Utilities.MixedRealityPose>, Microsoft.MixedReality.Toolkit.Input.IMixedRealityInputHandler<UnityEngine.Vector2>, Microsoft.MixedReality.Toolkit.Input.IMixedRealityInputHandler<UnityEngine.Vector3>, Microsoft.MixedReality.Toolkit.Input.IMixedRealitySpeechHandler, Microsoft.MixedReality.Toolkit.Input.IMixedRealityTouchHandler, UnityEngine.EventSystems.IEventSystemHandler
[<UnityEngine.AddComponentMenu("Scripts/MRTK/SDK/Interactable")>]
[<UnityEngine.HelpURL("https://docs.microsoft.com/windows/mixed-reality/mrtk-unity/features/ux-building-blocks/interactable")>]
[<System.Serializable>]
type Interactable = class
    inherit MonoBehaviour
    interface IMixedRealityFocusChangedHandler
    interface IEventSystemHandler
    interface IMixedRealityFocusHandler
    interface IMixedRealityInputHandler
    interface IMixedRealityBaseInputHandler
    interface IMixedRealitySpeechHandler
    interface IMixedRealityTouchHandler
    interface IMixedRealityInputHandler<Vector2>
    interface IMixedRealityInputHandler<Vector3>
    interface IMixedRealityInputHandler<MixedRealityPose>
Public Class Interactable
Inherits MonoBehaviour
Implements IEventSystemHandler, IMixedRealityFocusChangedHandler, IMixedRealityFocusHandler, IMixedRealityInputHandler, IMixedRealityInputHandler(Of MixedRealityPose), IMixedRealityInputHandler(Of Vector2), IMixedRealityInputHandler(Of Vector3), IMixedRealitySpeechHandler, IMixedRealityTouchHandler
Inheritance
UnityEngine.MonoBehaviour
Interactable
Attributes
UnityEngine.AddComponentMenuAttribute UnityEngine.HelpURLAttribute SerializableAttribute
Implements

Constructors

Interactable()

Fields

CanDeselect

Can the user deselect a toggle? A radial button or tab should set this to false

CanSelect

Is the interactive selectable? When a multi-dimension button, can the user initiate switching dimensions?

clickTime

A click must occur within this many seconds after an input down

clickValidTimer
dimensionIndex
Dimensions

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

dragStartPosition

The position of the controller when input down occurs. Used to determine when controller has moved far enough to trigger gesture

focusingPointers
forceUpdate
globalFeedbackClickTime

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

globalTimer
handlers
isGlobal
lastState
OnClick

Base onclick event

pressingInputSources
rollOffTimer
VoiceCommand

This string keyword is the voice command that will fire a click on this Interactable.

voiceRequiresFocus

Properties

ActiveThemes

The list of running theme instances to receive state changes When the dimension index changes, activeThemes updates to those assigned to that dimension.

ButtonMode

Returns the current selection mode of the Interactable based on the number of Dimensions available

ClickCount

How many times this interactable was clicked

CurrentDimension

Current Dimension index based zero and must be less than Dimensions

Enabled
Obsolete.

Is the interactable enabled?

FocusEnabled
Obsolete.

Does this interactable require focus

FocusingPointers

Pointers that are focusing the interactable

HasCollision

State that corresponds to Interactable is touching another object

HasCustom

State that corresponds to miscellaneous/custom use by consumers Currently not controlled by Interactable directly

HasFocus

Has focus

HasGesture

Currently pressed and some movement has occurred

HasGestureMax

State that corresponds to Gesture reaching max threshold or limits

HasGrab

A near interaction grabbable is actively being grabbed

HasObservation

State that corresponds to no focus,and finger is down. Currently not controlled by Interactable directly

HasObservationTargeted

State that corresponds to has focus,and finger down. Currently not controlled by Interactable directly

HasPhysicalTouch

A near interaction touchable is actively being touched

HasPress

Currently being pressed

HasVoiceCommand

A voice command has just occurred

InputAction

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

InteractableEvents

List of events added to this interactable

IsDisabled
Obsolete.

Is disabled

IsEnabled

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.

IsGlobal

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.

IsInteractive

State that corresponds to no focus,and finger is up. Currently not controlled by Interactable directly

IsTargeted

Targeted means the item has focus and finger is up Currently not controlled by Interactable directly

IsToggleButton
Obsolete.

True if Selection is "Toggle" (Dimensions == 2)

IsToggled

Determines whether Interactable is toggled or not. If true, CurrentDimension should be 1 and if false, CurrentDimension should be 0

IsVisited

The Interactable has been clicked

NumOfDimensions

A way of adding more layers of states for controls like toggles

PressingInputSources

Input sources that are pressing the interactable

Profiles

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

RequiresFocus
Obsolete.

Do voice commands require focus?

ResetOnDestroy

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.

RollOffTime

Allows for switching colliders without firing a lose focus immediately for advanced controls like drop-downs

StateManager

The state logic class for storing and comparing states which determines the current value.

States

ScriptableObject to reference for basic state logic to follow when interacting and transitioning between states. Should generally be "DefaultInteractableStates" object

VoiceCommand

This string keyword is the voice command that will fire a click on this Interactable.

VoiceRequiresFocus

Does the voice command require this to have focus? Registers as a global listener for speech commands, ignores input events

Methods

AddHandler(IInteractableHandler)

Register OnClick extra handlers

AddReceiver<T>()

Event receivers can be used to listen for different events at runtime. This method allows receivers to be dynamically added at runtime.

Awake() UnityEngine.MonoBehaviour.Awake
CanInteract()

Based on button settings and state, should this button listen to input?

ConvertToSelectionMode(Int32)

Helper method to convert number of dimensions to the appropriate SelectionModes

DecreaseDimension()

Decreases the Current Dimension by 1. If at zero, then loop around to end (i.e Dimensions - 1)

ForceUpdateThemes()
Obsolete.

Force re-initialization of Interactable from events, themes and state references

GetDefaultInteractableStates()

Creates the default States ScriptableObject configured for Interactable

GetDefaultThemeAsset(List<ThemeDefinition>)

Helper function to create a new Theme asset using Default Interactable States and provided theme definitions

GetDimensionIndex()
Obsolete.

A public way to access the current dimension

GetReceiver<T>()

Returns the first receiver of type T on the interactable, or null if nothing is found.

GetReceivers<T>()

Returns all receivers of type T on the interactable. If nothing is found, returns empty list.

GetStates()
Obsolete.

Returns a list of states assigned to the Interactable

GetStateValue(InteractableStates+InteractableStateEnum)

Grabs the state value index, returns -1 if no StateManager available

GlobalVisualReset(Single)

Clears up any automated visual states

IncreaseDimension()

Increases the Current Dimension by 1. If at end (i.e Dimensions - 1), then loop around to beginning (i.e 0)

Initialize()
InputDownTimer(Single)

A timer for the MixedRealityInputHandlers, clicks should occur within a certain time.

OnBeforeFocusChange(FocusEventData)

Focus event that is raised before the focus is actually changed.

OnDestroy() UnityEngine.MonoBehaviour.OnDestroy
OnDisable() UnityEngine.MonoBehaviour.OnDisable
OnEnable() UnityEngine.MonoBehaviour.OnEnable
OnFocusChanged(FocusEventData)

Focus event that is raised when the focused object is changed.

OnFocusEnter(FocusEventData)

The Focus Enter event is raised on this GameObject whenever a IMixedRealityPointer's focus enters this GameObject's Collider.

OnFocusExit(FocusEventData)

The Focus Exit event is raised on this GameObject whenever a IMixedRealityPointer's focus leaves this GameObject's Collider.

OnInputChanged(InputEventData<MixedRealityPose>)

Raised input event updates from the type of input specified in the interface handler implementation.

OnInputChanged(InputEventData<Vector2>)

Raised input event updates from the type of input specified in the interface handler implementation.

OnInputChanged(InputEventData<Vector3>)

Raised input event updates from the type of input specified in the interface handler implementation.

OnInputDown(InputEventData)

Input Down updates from Interactions, Keys, or any other simple input.

OnInputUp(InputEventData)

Input Up updates from Interactions, Keys, or any other simple input.

OnPositionInputChanged(InputEventData<Vector2>) UnityEngine.MonoBehaviour.OnPositionInputChanged(Microsoft.MixedReality.Toolkit.Input.InputEventData{UnityEngine.Vector2})
OnSpeechKeywordRecognized(SpeechEventData)

Voice commands from MixedRealitySpeechCommandProfile, keyword recognized

OnTouchCompleted(HandTrackingInputEventData)
OnTouchStarted(HandTrackingInputEventData)
OnTouchUpdated(HandTrackingInputEventData)
RefreshSetup()

Force re-initialization of Interactable from events, themes and state references

RemoveHandler(IInteractableHandler)

Remove onClick handlers

ResetAllStates()

Reset all states in the Interactable and pointer information

ResetBaseStates()
Obsolete.

Resets input tracking states such as focus or grab that are directly controlled by Interactable

ResetInputTrackingStates()

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

ResolveInputAction(Int32)

Assigns the InputAction based on the InputActionId

SendOnClick(IMixedRealityPointer)

Call onClick methods on receivers or IInteractableHandlers

SendVoiceCommands(String, Int32, Int32)

call OnVoinceCommand methods on receivers or IInteractableHandlers

SetCollision(Boolean)
Obsolete.

Change the collision state

SetCustom(Boolean)
Obsolete.

Change the custom state

SetDimensionIndex(Int32)
Obsolete.

a public way to set the dimension index

SetDisabled(Boolean)
Obsolete.

Change the disabled state, will override the Enabled property

SetFocus(Boolean)
Obsolete.

Handle focus state changes

SetGesture(Boolean)
Obsolete.

Change the gesture state

SetGestureMax(Boolean)
Obsolete.

Change the gesture max state

SetGrab(Boolean)
Obsolete.

Change the grab state

SetInputDown()

Public method that can be used to set state of interactable corresponding to an input going down (select button, menu button, touch)

SetInputUp()

Public method that can be used to set state of interactable corresponding to an input going up.

SetInteractive(Boolean)
Obsolete.

Change the Interactive state

SetObservation(Boolean)
Obsolete.

Change the observation state

SetObservationTargeted(Boolean)
Obsolete.

Change the observation targeted state

SetPhysicalTouch(Boolean)
Obsolete.

Change the physical touch state

SetPress(Boolean)
Obsolete.

Change the press state

SetState(InteractableStates+InteractableStateEnum, Boolean)

a public way to set state directly

SetTargeted(Boolean)
Obsolete.

Change the targeted state

SetToggled(Boolean)
Obsolete.

Change the toggled state

SetupEvents()

Creates the event receiver instances from the Events list

SetupStates()

starts the StateManager

SetVisited(Boolean)
Obsolete.

Change the visited state

SetVoiceCommand(Boolean)
Obsolete.

Change the voice command state

ShouldListenToUpDownEvent(InputEventData)

Based on inputAction and state, should interactable listen to this up/down event.

Start() UnityEngine.MonoBehaviour.Start
StartClickTimer(Boolean)

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
StartGlobalVisual(Boolean)

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

StopClickTimer()
TriggerOnClick()

A public way to trigger or route an onClick event from an external source, like PressableButton

TriggerOnClick(Boolean)

A public way to trigger or route an onClick event from an external source, like PressableButton

Update() UnityEngine.MonoBehaviour.Update
UpdateActiveThemes()

Updates the list of active themes based the current dimensions index

UpdateState()

runs the state logic and sets state based on the current state values

Applies to