Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access Events "OnToggled" and "OnUntoggled" of a PressableButton? #11812

Closed
ArDevKarl opened this issue Feb 13, 2024 · 1 comment
Closed

Comments

@ArDevKarl
Copy link

I replaced all my toggles with the new PressableButton of the MRTK3. Before the update, I subscribed to "onValueChanged" of my Toggle element. Now this event does not exist anymore. The PressableButton offers "OnToggled" and "OnUntoggled" in the inspector. I cannot find the right way, to access these events in my code.

The docu talks about the StatefulInteractable. But even this class does not offer those events. I could use some help.

Screenshot 2024-02-13 100225

@AMollis
Copy link
Member

AMollis commented Feb 13, 2024

Use the StatefulInteractable.IsToggled TimedFlag object. Types of TimedFlag have an OnEntered and OnExited event you can register to.

https://learn.microsoft.com/en-us/dotnet/api/mixedreality.toolkit.statefulinteractable.istoggled?view=mrtkcore-3.0&viewFallbackFrom=mrtkuxcore-3.0#mixedreality-toolkit-statefulinteractable-istoggled

https://learn.microsoft.com/en-us/dotnet/api/mixedreality.toolkit.timedflag?view=mrtkcore-3.0

private void AddEventHandlers(PressableButton button)
{
    button.IsToggled.OnEntered.AddListener(OnButtonToggledEntered);
    button.IsToggled.OnExited.AddListener(OnButtonToggledExited);
}

private void RemoveEventHandlers(PressableButton button)
{
    button.IsToggled.OnEntered.RemoveListener(OnButtonToggledEntered);
    button.IsToggled.OnExited.RemoveListener(OnButtonToggledExited);
}

private void OnButtonToggledEntered(float value)
{
}

private void OnButtonToggledExited(float value)
{
}

@AMollis AMollis closed this as completed Feb 13, 2024
@AMollis AMollis reopened this Feb 13, 2024
@microsoft microsoft locked and limited conversation to collaborators Feb 13, 2024
@AMollis AMollis converted this issue into discussion #11813 Feb 13, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

2 participants