C# 全息透镜101第三章:什么是=&燃气轮机&引用;对于

C# 全息透镜101第三章:什么是=&燃气轮机&引用;对于,c#,lambda,hololens-emulator,C#,Lambda,Hololens Emulator,在第3章GazeGestureManager.cs中: using UnityEngine; using UnityEngine.VR.WSA.Input; public class GazeGestureManager : MonoBehaviour { public static GazeGestureManager Instance { get; private set; } // Represents the hologram that is currently be

在第3章GazeGestureManager.cs中:

using UnityEngine;
using UnityEngine.VR.WSA.Input;

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();
    }

    // Update is called once per frame
    void Update()
    {
        // Figure out which hologram is focused this frame.
        GameObject oldFocusObject = FocusedObject;

        // Do a raycast into the world based on the user's
        // head position and orientation.
        var headPosition = Camera.main.transform.position;
        var gazeDirection = Camera.main.transform.forward;

        RaycastHit hitInfo;
        if (Physics.Raycast(headPosition, gazeDirection, out hitInfo))
        {
            // If the raycast hit a hologram, use that as the focused object.
            FocusedObject = hitInfo.collider.gameObject;
        }
        else
        {
            // If the raycast did not hit a hologram, clear the focused object.
            FocusedObject = null;
        }

        // If the focused object changed this frame,
        // start detecting fresh gestures again.
        if (FocusedObject != oldFocusObject)
        {
            recognizer.CancelGestures();
            recognizer.StartCapturingGestures();
        }
    }
}
我真的不明白这句话:

recognizer.TappedEvent += (source, tapCount, ray) =>

()
里面是什么,为什么有一个
=>
操作符,它是用来做什么的?

看看C#Lambda操作符。它将块与左侧的输入变量分开。因此,看起来块将在抽头事件上执行,参数(源、抽头计数、射线)将被传递并可在块中使用。

看看C#Lambda操作符。它将块与左侧的输入变量分开。因此,看起来块将在抽头事件上执行,参数(source、tapCount、ray)将被传递并可在块中使用。

我喜欢将其视为“处理事件或回调的内联委托”。希望这会有所帮助:)

我喜欢将其视为“处理事件或回调的内联委托”。希望有帮助:)