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");
}
void IMixedRealityFocusHandler.OnFocusEnter(FocusEventData eventData)
{
}
void IMixedRealityFocusHandler.OnFocusExit(FocusEventData eventData)
{
}
void IMixedRealityPointerHandler.OnPointerClicked(MixedRealityPointerEventData eventData)
{
Debug.Log("OnPointerClicked");
}
void IMixedRealityPointerHandler.OnPointerDown(MixedRealityPointerEventData eventData)
{
}
void IMixedRealityPointerHandler.OnPointerDragged(MixedRealityPointerEventData eventData)
{
}
void IMixedRealityPointerHandler.OnPointerUp(MixedRealityPointerEventData eventData)
{
}
void Update()
{
hitObj = Camera.main.GetComponent<GazeProvider>().GazeTarget;
if (hitObj)
{
Debug.Log("输出检测到的物体 " + hitObj.name);
}
}
}