Hololens与UI的交互,检测物体以及常见手势

Hololens与UI的交互,检测物体以及常见手势

using System.Collections;
using System.Collections.Generic;
using Microsoft.MixedReality.Toolkit.Input;
using UnityEngine;
using UnityEngine.XR.WSA.Input;
using UnityEngine.EventSystems;
using System;

public class test : MonoBehaviour, IMixedRealityPointerHandler, IMixedRealityFocusHandler
{
    GestureRecognizer gestureRecognizer;
    GameObject hitObj; //视线中检测到的物体
    void Start()
    {
        gestureRecognizer = new GestureRecognizer();
        gestureRecognizer.HoldStarted += test2;
        gestureRecognizer.Tapped += test3;
        gestureRecognizer.StartCapturingGestures();

    }
    //检测到手机点下然后停留的时候触发
    void test2(HoldStartedEventArgs action )
    {
        Debug.Log("HoldStartedEventArgs");
    }
    //检测到手指点击的时候触发
    void test3(TappedEventArgs action)
    {
        Debug.Log("TappedEventArgs");
    }



    //以下需检测到物体才能触发
    //视野中的中心点进入UI
    void IMixedRealityFocusHandler.OnFocusEnter(FocusEventData eventData)
    {
        //Debug.Log("OnFocusEnter");
    }
    //视野中的中心点离开UI
    void IMixedRealityFocusHandler.OnFocusExit(FocusEventData eventData)
    {
        //Debug.Log("OnFocusExit");

    }
    //手指点击UI
    void IMixedRealityPointerHandler.OnPointerClicked(MixedRealityPointerEventData eventData)
    {
        Debug.Log("OnPointerClicked");
    }
    //手指按下UI
    void IMixedRealityPointerHandler.OnPointerDown(MixedRealityPointerEventData eventData)
    {
        //Debug.Log("OnPointerDown");

    }
    //手指长按UI
    void IMixedRealityPointerHandler.OnPointerDragged(MixedRealityPointerEventData eventData)
    {
        //Debug.Log("OnPointerDragged");

    }
    //手指抬起UI
    void IMixedRealityPointerHandler.OnPointerUp(MixedRealityPointerEventData eventData)
    {
        //Debug.Log("OnPointerUp");

    }

    void Update()
    {
        hitObj = Camera.main.GetComponent<GazeProvider>().GazeTarget;
        if (hitObj)
        {
            Debug.Log("输出检测到的物体 " + hitObj.name);
        }
    }
}

你可能感兴趣的:(unity)