microsoft / MixedRealityToolkit-Unity

This repository is for the legacy Mixed Reality Toolkit (MRTK) v2. For the latest version of the MRTK please visit https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity
https://aka.ms/mrtkdocs
MIT License
6k stars 2.12k forks source link

Add UnityEvent support #107

Closed stbertou closed 8 years ago

stbertou commented 8 years ago

Hi guys

I think it would be really useful to make the HoloToolKit work nicely with Unity's Event system. Basically invoking an event for when we gaze (OnGazeEnter / OnGazeLeave), when we select (OnSelectObject / OnClearSelection) etc..

I've prototyped it already, happy to put a PR if you also think that would be useful !

stbertou commented 8 years ago

Pretty simple as you can see!

public class OnGazeEnterEvent : MonoBehaviour
{
    public UnityEvent Event;
    public void OnGazeEnter()
    {
        if (Event != null)
        {
            Event.Invoke();
        }
    }
}
stbertou commented 8 years ago

I've prototyped, it works well and you can litterally do "anything" as you can now invoke an event from a gaze interaction For the selection side, it looks like we have 2 similar-ish messages already : OnSelect and OnSelectObject Any idea what the difference is ?

Subere23 commented 8 years ago

That seems like a great idea

NeerajW commented 8 years ago

@stbertou sounds like a great idea and one step closer to moving towards more polymorphic code :) How about you start with Gaze and OnSelect events? The SelectObject events are for sending messages to focused objects which help tie them with keywords manager.

This is also a good opportunity to think through the event names :)

stbertou commented 8 years ago

Here you go: https://github.com/Microsoft/HoloToolkit-Unity/pull/109