Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.

Click to Activate and Deactivate

Hi,
The situation that I have, its a multi object model with a details panel (3D Cube with Text as child) above it. I would like to have a details panel appear whenever its object is clicked on. If another object is selected the current active details panel will disappear and the new objects detail panel will appear in its place.
Any suggestion about the best way to approach this or code required that I could reference?
Thanks!!

Tagged:

Best Answer

  • holonutholonut
    Accepted Answer

    Thanks for the input! I will try everything suggested.

Answers

  • I should specify that it will be for AirTap not click. I am developing for Hololens.
    Thanks!

  • Depending on if you're using Unity or DirectX - the concept is the same but the way you do it is different.

    Concept: in an air-tap event, perform a hit test with your cursor/gaze, check it's state (active/not active/showing details/not showing) the determine the action you want to display based on hit test, click event and state. You have to come up with a way to maintain state.

    HTH

    Dwight Goins
    CAO & Founder| Independent Architect | Trainer and Consultant | Sr. Enterprise Architect
    MVP | MCT | MCSD | MCPD | SharePoint TS | MS Virtual TS |Windows 8 App Store Developer | Linux Gentoo Geek | Raspberry Pi Owner | Micro .Net Developer | Kinect For Windows Device Developer
    http://dgoins.wordpress.com

  • Sorry the software I am using is Unity.
    I understand your concept but I don’t know what the best script I should use to achieve this. Unfortunately I am new to c# and unity so please be patient.
    Thanks!
  • If you are trying to get something like an OnClick event but for Air Taps then it is pretty easy to do. Implement the IInputClickHandler from the HoloToolkit. You will also need to get the interface method:

    public void OnInputClicked(InputClickedEventData eventData)

    Then in your Start function add this line of code in order to start the listener.

    InputManager.Instance.AddGlobalListener(gameObject);

    You will also need to add this to your project:

    using HoloToolkit.Unity.InputModule;

    AR Developer

  • I will try this. Thanks!

  • I guess I am not on the right track...

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using HoloToolkit.Unity.InputModule;

    public class ClickToActivateandDeactivate : MonoBehaviour, IInputClickHandler
    {
    private GameObject DetailsBilloard;
    private GameObject Clutch_Gaurd_Cube;
    private GameObject Electromagnetic_Toothed_Coupling_Clutch_Cube;
    private GameObject Input_Shaft_Cube;
    private GameObject M10_120_imbus_Spring_Cube;
    private GameObject Clutch_Billboard;

    public void OnInputClicked(InputClickedEventData eventData)
    {
        if (Clutch_Gaurd_Cube.GetComponent<MeshRenderer>().enabled == true)
        {
            Clutch_Gaurd_Cube.GetComponent<MeshRenderer>().enabled = false;
            Clutch_Billboard.GetComponent<MeshRenderer>().enabled = true;
        }
        else
        {
            Clutch_Gaurd_Cube.GetComponent<MeshRenderer>().enabled = true;
            Clutch_Billboard.GetComponent<MeshRenderer>().enabled = false;
            Electromagnetic_Toothed_Coupling_Clutch_Cube.GetComponent<MeshRenderer>().enabled = false;
            Input_Shaft_Cube.GetComponent<MeshRenderer>().enabled = false;
            M10_120_imbus_Spring_Cube.GetComponent<MeshRenderer>().enabled = false;
        }
    }
    

    }

    Any suggestions would be appreciated!

  • What is the problem you are having?

    AR Developer

  • I am not able to have a gameobject (Clutch_Gaurd_Cube) popup when I air tap on the gameobject assigned with this C# script. (Nothing happens)
    I've imported an fbx prefab and have inserted it into the scene. All prefabs have their own popup detail cubes (with child text) assigned to it. When I air tap onto one piece of the prefab I want to have its details gameobject (Clutch_Gaurd_Cube) show up. If I air tap onto this same prefab piece and its detail gameobject (Clutch_Gaurd_Cube) is already active then another details gameobject will appear (Clutch_Billboard).
    Also, if I air tap onto a completely different prefab gameobject within the scene I want to have a different details cube appear in its place. (eg. Input_Shaft_Cube)
    I hope this make sense...

  • Did you put this line of code in your start method?

    InputManager.Instance.AddGlobalListener(gameObject);

    AR Developer

  • I added it to my script and still change in DetailsBillboard when I airtap on the gameobject with this script attached to it. I don't know what I'm missing...

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using HoloToolkit.Unity.InputModule;

    public class ClickToActivateandDeactivate : MonoBehaviour, IInputClickHandler
    {
    private GameObject DetailsBilloard;
    private GameObject Clutch_Gaurd_Cube;
    private GameObject Electromagnetic_Toothed_Coupling_Clutch_Cube;
    private GameObject Input_Shaft_Cube;
    private GameObject M10_120_imbus_Spring_Cube;
    private GameObject Clutch_Billboard;

    public void OnInputClicked(InputClickedEventData eventData)
    {
        InputManager.Instance.AddGlobalListener(gameObject);
        if (Clutch_Gaurd_Cube.GetComponent<MeshRenderer>().enabled == true)
        {
            Clutch_Gaurd_Cube.GetComponent<MeshRenderer>().enabled = false;
            Clutch_Billboard.GetComponent<MeshRenderer>().enabled = true;
        }
        else
        {
            Clutch_Gaurd_Cube.GetComponent<MeshRenderer>().enabled = true;
            Clutch_Billboard.GetComponent<MeshRenderer>().enabled = false;
            Electromagnetic_Toothed_Coupling_Clutch_Cube.GetComponent<MeshRenderer>().enabled = false;
            Input_Shaft_Cube.GetComponent<MeshRenderer>().enabled = false;
            M10_120_imbus_Spring_Cube.GetComponent<MeshRenderer>().enabled = false;
        }
    }
    

    }

  • dbarrettdbarrett ✭✭✭
    edited November 2017

    Don't add it in the OnInputClicked method. Add a Start method and put it in there.

    ` public class ClickToActivateandDeactivate : MonoBehaviour, IInputClickHandler
    {
    private GameObject DetailsBilloard;
    private GameObject Clutch_Gaurd_Cube;
    private GameObject Electromagnetic_Toothed_Coupling_Clutch_Cube;
    private GameObject Input_Shaft_Cube;
    private GameObject M10_120_imbus_Spring_Cube;
    private GameObject Clutch_Billboard;

    private void Start()
    {
         InputManager.Instance.AddGlobalListener(gameObject);
    }
    
    public void OnInputClicked(InputClickedEventData eventData)
    {
            if (Clutch_Gaurd_Cube.GetComponent<MeshRenderer>().enabled == true)
        {
            Clutch_Gaurd_Cube.GetComponent<MeshRenderer>().enabled = false;
            Clutch_Billboard.GetComponent<MeshRenderer>().enabled = true;
        }
        else
        {
            Clutch_Gaurd_Cube.GetComponent<MeshRenderer>().enabled = true;
            Clutch_Billboard.GetComponent<MeshRenderer>().enabled = false;
            Electromagnetic_Toothed_Coupling_Clutch_Cube.GetComponent<MeshRenderer>().enabled = false;
            Input_Shaft_Cube.GetComponent<MeshRenderer>().enabled = false;
            M10_120_imbus_Spring_Cube.GetComponent<MeshRenderer>().enabled = false;
        }
    }
    }`
    

    AR Developer

  • dbarrettdbarrett ✭✭✭
    edited November 2017

    You need to add it in your Start method not OnInputClicked

    void Start() {

    InputManager.Instance.AddGlobalListener(gameObject);
    

    }

    if this isn't working in the editor you usually have to press the space key along with a mouse click in order to perform an air tap.

    Also if you are destroying this object you need to add an OnDestroy method and remove the listener.

    void OnDestroy() {

    InputManager.Instance.RemoveGlobalListener(gameObject);
    

    }

    AR Developer

  • holonutholonut
    Accepted Answer

    Thanks for the input! I will try everything suggested.

Sign In or Register to comment.