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.

Holograms 101E Chapter 3 - Gestures

I am trying to understand the code for Gesturemanager.cs
1. What does the instance variable actually do in this case? (After initializing it, it didnt called anywhere).
2. What is += and => means?
3. what is source,tapcount and ray, is there api documentation for this?

public class GazeGestureManager : MonoBehaviour
{
public static GazeGestureManager Instance { get; private set; }

// Represents the hologram that is currently being gazed at.
public GameObject FocusedObject { get; private set; }

GestureRecognizer recognizer;

// Use this for initialization
void Start()
{
    **Instance = this;**

    // Set up a GestureRecognizer to detect Select gestures.
    recognizer = new GestureRecognizer();
    **recognizer.TappedEvent += (source, tapCount, ray) =>**
    {
        // Send an OnSelect message to the focused object and its ancestors.
        if (FocusedObject != null)
        {
            FocusedObject.SendMessageUpwards("OnSelect");
        }
    };
    recognizer.StartCapturingGestures();
}
Tagged:

Best Answer

  • HoloSheepHoloSheep mod
    Answer ✓

    Hi @Kapo,

    1 The GazeGestureManager class is implementing a Singleton pattern so that only one instance of the class gets created. Note that Instance is declared a few lines above as a property of the class

    public static GazeGestureManager Instance { get; private set; }

    in the line you highlight it is getting set to the current instance so that it can be referenced externally as a property of that singleton instance.

    2 The two C# expressions you ask about are:

    += syntax for adding an event handler

    => syntax for assigning a Lambda Expression

    3 The three variables: source, tap and ray are the event arguments that recognizer event will pass back (in this case to the Lambda expression which is the assigned event handler). The GestureRecognizer class comes from the UnityEngine.VR.WSA.Input namespace and that class implements the TappedEvent that would define the three arguments that you are asking about. Unfortunately with the HTP still being in beta the documentation on the API is still a little scarce.

    The following page of the documentation may be of some help.

    Windows Holographic User Group Redmond

    WinHUGR.org - - - - - - - - - - - - - - - - - - @WinHUGR
    WinHUGR YouTube Channel -- live streamed meetings

Answers

  • HoloSheepHoloSheep mod
    Answer ✓

    Hi @Kapo,

    1 The GazeGestureManager class is implementing a Singleton pattern so that only one instance of the class gets created. Note that Instance is declared a few lines above as a property of the class

    public static GazeGestureManager Instance { get; private set; }

    in the line you highlight it is getting set to the current instance so that it can be referenced externally as a property of that singleton instance.

    2 The two C# expressions you ask about are:

    += syntax for adding an event handler

    => syntax for assigning a Lambda Expression

    3 The three variables: source, tap and ray are the event arguments that recognizer event will pass back (in this case to the Lambda expression which is the assigned event handler). The GestureRecognizer class comes from the UnityEngine.VR.WSA.Input namespace and that class implements the TappedEvent that would define the three arguments that you are asking about. Unfortunately with the HTP still being in beta the documentation on the API is still a little scarce.

    The following page of the documentation may be of some help.

    Windows Holographic User Group Redmond

    WinHUGR.org - - - - - - - - - - - - - - - - - - @WinHUGR
    WinHUGR YouTube Channel -- live streamed meetings

  • Thanks for the reply, another questions about this chapter.

    How did the onSelect() called by GazeGestureManager from SphereCommands script?
    It does not reference GazeGestureManager at all and we did not create any method on GazeGestureManager either.

  • @Kapo,

    Unity has a set of methods (SendMessage, for example) that calls the named function on a target GameObject, if the method is defined. The SphereCommands script, attached to the Sphere1 and Sphere2 GameObjects provides that method.

    Hope this clarifies things.

    Thanks!
    David

  • behrambehram
    edited August 2016

    Hello @kapo read my thread asking about the onSelect() method on the Unity Hololens forums. They have provided a really good explanation.

    Gaze Gesture Manager : help deconstructing void Start() script
    forum.unity3d.com/threads/origami-tutorial-gaze-gesture-manager-help-deconstructing-void-start-script.412459/?_ga=1.88598488.2106007873.1462271780

    I was in a similar situation like you a while ago trying to understand this whole Event,Delegate & lambda expression business.

    Paid:
    3 videos from Mosh Hamedani's Udemy course made everything clear:
    https://www.udemy.com/csharp-advanced/learn/v4/overview
    Free:
    https://www.youtube.com/watch?v=jQgwEsJISy0

    Free:
    Understanding Event-Driven Programming
    https://channel9.msdn.com/Series/C-Fundamentals-for-Absolute-Beginners/24

    cheers,
    b

Sign In or Register to comment.