Skip to content
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

Custom buttons on AppBar raise no event #1835

Closed
GermainJLab opened this Issue Mar 14, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@GermainJLab
Copy link

GermainJLab commented Mar 14, 2018

Overview

When adding custom buttons on the AppBar, those buttons do not raise any event when clicked, even though an OnTappedEvent has been provided.

Expected Behavior

When clicked the buttons should raise their OnTappedEvent.

Actual Behavior

Nothing happens on click.

Steps to reproduce

Just add an OnTappedEvent on a custom event and nothing happens on click.

Unity Editor Version

2017.2.1f1

Mixed Reality Toolkit Release Version

Actual Dev_Working_Branch.

Correction Proposed

Not sure if we are just not using the AppBar correctly. We added a behaviour in the InputClicked method of the AppBar.cs and added a getter on the template attribute of the AppBarButton.cs :

lignes 239-241 :

default:
obj.GetComponent().getTemplate().OnTappedEvent.Invoke();
break;

@cre8ivepark

This comment has been minimized.

Copy link
Contributor

cre8ivepark commented Mar 15, 2018

@GermainJLab We found that OnTappedEvent is no longer used. We'll remove it from the AppBar inspector. You can simply add custom logic to InputClicked() function in AppBar.cs

  1. Add custom buttons. In this example, I have added with name ButtonSave and ButtonLoad
    2018-03-15 16_26_44-unity 2017 2 1f1 64bit - boundingboxgizmoexample unity - mrtk-original - unive

  2. In AppBar.cs

    protected override void InputClicked(GameObject obj, InputClickedEventData eventData)
     {
         if (Time.time < lastTimeTapped + coolDownTime)
         {
             return;
         }
    
         lastTimeTapped = Time.time;
         base.InputClicked(obj, eventData);
    
         textOutput.GetComponent<TextMesh>().text = obj.name;
    
         switch (obj.name)
         {
    
             case "ButtonSave":
                 // Do something for Save button
                 break;
    
             case "ButtonLoad":
                 // Do something for Load button";
                 break;
    
             case "Remove":
                 // Destroy the target object, Bounding Box, Bounding Box Rig and App Bar
                 boundingBox.Target.GetComponent<BoundingBoxRig>().Deactivate();
                 Component.Destroy(boundingBox.Target.GetComponent<BoundingBoxRig>());
                 GameObject.Destroy(boundingBox.Target);
                 GameObject.Destroy(this.gameObject);
                 break;
    
             case "Adjust":
                 // Make the bounding box active so users can manipulate it
                 State = AppBarStateEnum.Manipulation;
                 // Activate BoundingBoxRig
                 boundingBox.Target.GetComponent<BoundingBoxRig>().Activate();
                 break;
    
             case "Hide":
                 // Make the bounding box inactive and invisible
                 State = AppBarStateEnum.Hidden;
                 break;
    
             case "Show":
                 State = AppBarStateEnum.Default;
                 // Deactivate BoundingBoxRig
                 boundingBox.Target.GetComponent<BoundingBoxRig>().Deactivate();
                 break;
    
             case "Done":
                 State = AppBarStateEnum.Default;
                 // Deactivate BoundingBoxRig
                 boundingBox.Target.GetComponent<BoundingBoxRig>().Deactivate();
                 break;
    
    
             default:
                 break;
         }
     }
    

Or, you can create a new class which inherits InteractionReceiver, then assign it to Event Target field. We'll update the scene with these examples.
Thanks!

@GermainJLab

This comment has been minimized.

Copy link
Author

GermainJLab commented Mar 16, 2018

Thank you! Thought we could just add custom buttons and then their OnTappedEvent would be called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.