Skip to content

Instantly share code, notes, and snippets.

@dykarohora
Created February 2, 2017 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dykarohora/519645e35656c8fa3d3f46bc1d2dd46c to your computer and use it in GitHub Desktop.
Save dykarohora/519645e35656c8fa3d3f46bc1d2dd46c to your computer and use it in GitHub Desktop.
Use event system instead of message system.
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.VR.WSA.Input;
public class GazeGestureManager : MonoBehaviour {
public static GazeGestureManager Instance { get; private set; }
public GameObject FocusedObject { get; private set; }
GestureRecognizer recognizer;
private void Awake() {
Instance = this;
recognizer = new GestureRecognizer();
recognizer.TappedEvent += (source, tapCount, ray) => {
if (FocusedObject != null) {
//FocusedObject.SendMessageUpwards("OnSelect");
ExecuteEvents.Execute<ISelectable>(
target: FocusedObject,
eventData: null,
functor: (target, data) => {
target.OnSelect();
});
}
};
recognizer.StartCapturingGestures();
}
// Update is called once per frame
void Update () {
GameObject oldFocusObject = FocusedObject;
var headPosition = Camera.main.transform.position;
var gazeDirection = Camera.main.transform.forward;
RaycastHit hitInfo;
if(Physics.Raycast(headPosition, gazeDirection, out hitInfo)) {
FocusedObject = hitInfo.collider.gameObject;
} else {
FocusedObject = null;
}
if(FocusedObject != oldFocusObject) {
recognizer.CancelGestures();
recognizer.StartCapturingGestures();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment