microsoft/MixedRealityToolkit-Unity

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

ArDevKarl opened this issue · 1 comments

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

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)
{
}