Skip to content

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

Closed

Description

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

Activity

  1. AMollis commented on Feb 13, 2024

    @AMollis
    Contributor

    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)
    {
    }
  2. locked and limited conversation to collaborators on Feb 13, 2024
  3. converted this issue into a discussion #11813 on Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions