MixedRealityToolkit-Unity icon indicating copy to clipboard operation
MixedRealityToolkit-Unity copied to clipboard

Need documentation on how to trigger interactables from code

Open genereddick opened this issue 7 years ago • 6 comments

Describe the problem

A couple of patterns for Interactables need documentation: a) How to change state in code:

  • Example use case: Checking a checkbox triggers an OnClick Event set up in Inspector and hides an object. Tapping the object also hides it, and should cause the checkbox to show as checked. How would this be done in code?

b) Setting / changing defaults at start. Ideally this would be done by exposing some settings in the Inspector (see #3603), but alternately an explanation of how to accomplish this either in code, or by changing the Profile templates.

genereddick avatar Apr 17 '19 21:04 genereddick

@killerantz Could you please help with this?

cre8ivepark avatar Apr 18 '19 04:04 cre8ivepark

We can show some better examples for things like the checkbox.

Just to break a few things apart to make sure we are talking about the same things. State in the Interactable refers to things like Focus, Press, visited, disabled. These can be set through code using SetFocus(true) or SetFocus(false). All the supported states have a setter.

This doesn't seem to be what @genereddick is referring to with the checkbox state. In order to not confused things like checked, toggled, selected with the basic interactive states and because the way the themes work in these alternative states I came up with Dimensions. Meaning a button can be focused and checked, in this case we may want to use a different theme to visually reflect this combination.

This is weird, but to change the Dimension of the Interactable, which is more of a cyclical thing, use the method SetDimensionIndex(0) for normal, or SetDimensionIndex(1) for checked. This whole system is controlled by the property Dimensions, which enables the Interactable to assign multiple themes to each target, one for each dimension. There are properties for Can Select and Can Deselect, but we could also add a default value here. These settings are only shown when Dimensions is set two or more.

image

To handle the toggle events, click the Add Event button at the bottom of the component and select "InteractableToggleReceiver" from the drop down. This will expose the OnSelect and OnDeselect events to make something turn on when the check box is checked or turn off when it is unchecked or whatever you want. You can also check the Dimension in code using GetDimensionIndex().

image

The InteractableToggleCollection component on the RadialSet example has code that controls the radial buttons toggled state (or DimensionIndex) and setting the currentIndex in the inspector will set the default selected radial button.

image

Part of the idea behind dimensions is having worked on some UI with buttons that have 3 or 4 stages, like a button that can control sizes like small, medium, and large. Each time the button is clicked the item it controls switches to the next size then cycles back to the beginning. The interesting thing about these types of controls like checkboxes compared to other buttons is a traditional button tells the user what will happen when clicked whereas the checkbox reflects the current status of a thing.

killerantz avatar Apr 18 '19 18:04 killerantz

@killerantz Thanks, that is clearer already, something like this in the documentation would be great.

It helps me to think of the focus, clicked, toggled, et.al. explicitly as "interactive states" to differentiate them from Dimensions as a cyclical state.

I think there definitely should be a public property for Dimension default index -- shouldn't have to set it in code unless you need to.

genereddick avatar Apr 19 '19 04:04 genereddick

Could we add the notes here into our doc page?

Yoyozilla avatar Apr 23 '19 20:04 Yoyozilla

Created a PR #4145, some of this is in the docs but may not be clear because of the way the sections are broken out.

killerantz avatar May 01 '19 20:05 killerantz

I think that a bunch of this was addressed, feel free to reopen if there were things not covered by @killerantz's PR.

wiwei avatar May 15 '19 01:05 wiwei