Hello everyone,
I’m using the gaze raycaster with the PointerEventData, this script has been working excellent since Unity 5, but now with the new release of Unity 5.4 it has stopped working, with Unity 5.4 seems like the central point has a weird offset.
Right now I’m totally lost, I don’t know what could be the problem, not sure what Unity have changed or how/where can I start to solve the problem, any help is much appreciated, thank you very much.
using UnityEngine;
using UnityEngine.EventSystems;
// An implementation of the BaseInputModule that uses the player's gaze as a raycast generator.
// To use, attach to the scene's EventSystem object. Set the Canvas
// object's Render Mode to World Space.
public class GazeGestureVR : BaseInputModule
{
// The pixel through which to cast rays, in viewport coordinates.
private Vector2 hotspot = new Vector2(0.5f, 0.5f);
private PointerEventData pointerData;
public override bool ShouldActivateModule()
{
return base.ShouldActivateModule();
}
public override void DeactivateModule()
{
base.DeactivateModule();
if (pointerData != null)
{
HandlePointerExitAndEnter(pointerData, null);
pointerData = null;
}
eventSystem.SetSelectedGameObject(null, GetBaseEventData());
}
public override bool IsPointerOverGameObject(int pointerId)
{
return pointerData != null && pointerData.pointerEnter != null;
}
public override void Process()
{
CastRayFromGaze();
UpdateCurrentObject();
}
private void CastRayFromGaze()
{
if (pointerData == null)
{
pointerData = new PointerEventData(eventSystem);
}
pointerData.Reset();
pointerData.position = new Vector2(hotspot.x * Screen.width, hotspot.y * Screen.height);
eventSystem.RaycastAll(pointerData, m_RaycastResultCache);
pointerData.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache);
m_RaycastResultCache.Clear();
}
private void UpdateCurrentObject()
{
// Send enter events and update the highlight.
var go = pointerData.pointerCurrentRaycast.gameObject;
HandlePointerExitAndEnter(pointerData, go);
// Update the current selection, or clear if it is no longer the current object.
var selected = ExecuteEvents.GetEventHandler<ISelectHandler>(go);
if (selected == eventSystem.currentSelectedGameObject)
{
ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, GetBaseEventData(),
ExecuteEvents.updateSelectedHandler);
}
else
{
eventSystem.SetSelectedGameObject(null, pointerData);
}
}
}