Я работаю над приложением YuGiOh HoloLens с некоторыми другими на github, и мы застряли на воздухозахватах. Я выполнил всю функциональность и протестировал ее с помощью функции OnMouseDown() Unity. Эта функция вызывается один раз при щелчке по объекту. Код между ними на самом деле не имеет значения, но я хотел показать, что не должно быть ничего фанкового.Как запустить воздухозаборник OnSelect Method точно один раз?
void OnMouseDown()
{
Debug.Log(myGameManager);
Debug.Log(myZone);
myGameManager.setSelectedCard(this, myZone);
}
Теперь я хочу airtap вместо щелчка, и поэтому мы сделали OnSelectMethod с этим кодом:
void OnSelect()
{
Debug.Log(myGameManager);
Debug.Log(myZone);
myGameManager.setSelectedCard(this, myZone);
}
и есть GazeGestureManager, который прикрепляется к объекту, который регистрирует событие. Мы вытащили этот код из Академии Hololens.
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?) Или что-то в этом роде?