-4

User can place objects (prefabs) at runtime using hands/gaze. Voice command ""Remove" should remove the current focussed (looked at) object.

I tried instantiating the objects and adding the Intractable script. But I am stuck add adding OnfocusEnter and OnfocusExit events at runtime.

Hooking up the events on the prefab wont work as the references are in the scene.

PeeteWard
  • 21
  • 4
  • 1
    You have a lot of statements in there but I don't see any real question. The best I can make out your question is your title, but that is a huge question and would require someone to write code for you, which is not the purpose of this site. Why not try writing some code to take the actions that you are describing and then ask questions here when you run into trouble. If you have no idea where to start, I'd suggest you go and watch the free Unity tutorials, which are excellent. – David Hoelzer May 31 '19 at 10:42
  • Please read this : https://stackoverflow.com/help/how-to-ask – Maifee Ul Asad May 31 '19 at 10:54
  • @DavidHoelzer this is a specific Hololens development mixed reality toolkit question as the tag suggests. Looking at your profile I don't see anything related to mrtk which is probably why you don't understand this simple question. – PeeteWard Jun 03 '19 at 08:03
  • @PeeteWard I assure you, we do a great deal of ar/Vr work. I simply rarely engage with questions here regarding it. As you can see from the other comment, I am not alone in finding your question lacking. Do not rely on profiles to determine someone’s expertise. – David Hoelzer Jun 03 '19 at 12:01
  • @DavidHoelzer This is not ar/vr its literally called Mixed Reality Toolkit. The question is simple I need to remove an object by voice command that the user focuses on. There is nothing more to explain if you have done mrtk dev you would know. – PeeteWard Jun 04 '19 at 07:58

2 Answers2

1

I worked this out over on GitHub and posting it here so we can remove it from the other sources.

I didn't tackle the voice input yet as I am not there yet on my own MRTK project.

This submission should cover this answer for MRTK under version RC1. This was a quick job just to show proof of concept - feel free to modify and go on with it but I won't be :)

For run-time placement you would just need to add a method to instantiate an object that contains all of the information I setup in this example. There were some other solutions in the GitHub channel, I've copied the links below (not sure how long they will be active). This example is assuming you have some sort of already default prefab with the MRTK interactable class part of it.

Other discussions on GitHub from Microsoft: https://github.com/microsoft/MixedRealityToolkit-Unity/issues/4456

Example Video is here: https://www.youtube.com/watch?v=47OExTOOuyU&feature=youtu.be

Example Unity Package is here: https://github.com/JShull/MRTKExamples

JShull
  • 11
  • 1
0

Based on @jShull answer I came up with a simple solution for what I needed. Since there is no global listener for focus events I basically made my own.

I also added an earlier discussion (before I posted the question here) with two Microsoft Developers of the Mixed Reality Toolkit which could help out of you are looking for more functionality: https://github.com/microsoft/MixedRealityToolkit-Unity/issues/4456

"Object" script that is a component of the object that needs to be removed or interacted with.

using Microsoft.MixedReality.Toolkit.Input;
using UnityEngine;

public class Object: MonoBehaviour, IMixedRealityFocusHandler
{
    public GameManager _gameManager;

    public void OnFocusEnter(FocusEventData eventData)
    {
        Debug.Log("Focus ON: " + gameObject);
        _gameManager.SetFocussedObject(gameObject);
    }

    public void OnFocusExit(FocusEventData eventData)
    {
        Debug.Log("Focus OFF: " + gameObject);
        _gameManager.ResetFocussedObject();
    }
}

"GameManager" script functions that sets the focussedObject

public void SetFocussedObject(GameObject object)
{
    focussedObject = object;
}

public void ResetFocussedObject()
{
    focussedObject = null;
}

Remove Object function is connect to the "Remove" global speech command in the "Speech Input Handler" component. It just removes the "focussedObject" inside the GameManager.

PeeteWard
  • 21
  • 4