07-02-2015 02:41 PM
07-02-2015 06:23 PM
07-02-2015 10:48 PM
using UnityEngine;
using UnityEngine.EventSystems;
using System.Collections.Generic;
public class GazeInputModule : PointerInputModule {
[Tooltip("Time in seconds for a gaze to click")]
public float GazeToClickTime = 2f;
private PointerEventData pointerEventData;
private GameObject currentLookAtHandler;
private float currentLookAtHandlerClickTime;
public override void Process()
{
ProcessGazeMove();
ProcessGazeClick();
}
void ProcessGazeMove()
{
if (pointerEventData == null)
{
pointerEventData = new PointerEventData(eventSystem);
}
// fake a pointer always being at the center of the screen
pointerEventData.position = new Vector2(Screen.width/2, Screen.height/2);
pointerEventData.delta = Vector2.zero;
List<RaycastResult> raycastResults = new List<RaycastResult>();
eventSystem.RaycastAll(pointerEventData, raycastResults);
pointerEventData.pointerCurrentRaycast = FindFirstRaycast(raycastResults);
ProcessMove(pointerEventData);
}
void ProcessGazeClick()
{
if (pointerEventData.pointerEnter != null)
{
// if the ui receiver has changed, reset the gaze delay timer
GameObject handler = ExecuteEvents.GetEventHandler<IPointerClickHandler>(pointerEventData.pointerEnter);
if (currentLookAtHandler != handler)
{
currentLookAtHandler = handler;
currentLookAtHandlerClickTime = Time.realtimeSinceStartup + GazeToClickTime;
}
// if we have a handler and it's time to click, do it now
if (currentLookAtHandler != null && Time.realtimeSinceStartup > currentLookAtHandlerClickTime)
{
ExecuteEvents.ExecuteHierarchy(currentLookAtHandler, pointerEventData, ExecuteEvents.pointerClickHandler);
currentLookAtHandlerClickTime = float.MaxValue;
}
}
else
{
currentLookAtHandler = null;
}
}
}
07-03-2015 12:38 PM
07-09-2015 06:29 PM
07-25-2015 08:25 PM
07-25-2015 11:11 PM