我正在与 github 上的其他一些人一起开发 YuGiOh HoloLens 应用程序,但我们被困在了 airtap 上。我已经完成了所有功能并使用 Unity 的 OnMouseDown() 函数对其进行了测试。单击对象时会调用该函数一次。两者之间的代码并不重要,但我想表明不应该有任何时髦的事情发生。
void OnMouseDown()
{
Debug.Log(myGameManager);
Debug.Log(myZone);
myGameManager.setSelectedCard(this, myZone);
}
现在我想点击而不是点击,所以我们使用以下代码执行了 OnSelectMethod:
void OnSelect()
{
Debug.Log(myGameManager);
Debug.Log(myZone);
myGameManager.setSelectedCard(this, myZone);
}
并且有一个 GazeGestureManager 附加到注册事件的对象上。我们从 Hololens Academy 提取了这段代码。
using UnityEngine;
using UnityEngine.VR.WSA.Input;
public class GazeGestureManager : MonoBehaviour
{
public static GazeGestureManager Instance { get; private set; }
private Vector3 moveDirection = Vector3.zero;
// 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();
}
}
}
现在我们已经多次使用此代码,并且我们设置它的任何方式 OnSelect() 方法都会被调用 4-36 次。为什么不只调用一次?
难道airtab是一个连续的事件?
在水龙头进行时,哪个会不断被轮询?如果是这样,是否有更适合使用的事件?(OnAirTapEnd?)或类似的东西?