In a previous project (using Oculus / Unity native VR), I custom-created a gaze-based selection system (ie. a timer is triggered upon entering a raycast collision, and an animated icon shows when the event will trigger if you keep looking at that object); however, it did not use UI / EventSystem / etc.
I’m trying to implement the same sort of setup for Cardboard, but finding it a little cumbersome to trace through all of the different references and instantiations to find where I would place a timer on enter/over event, and then use that to trigger the event when time is up.
Has somebody out there already done this and want to share the code, or is there something on the Asset store that will do this? (It’s a fairly simple task, and I wish the Cardboard components would simply have timed-gaze input as an option; in my case, touching a trigger or remote controller is not possible, I really need a timed gaze input, like this: VR Gaze Input | TALES FROM THE RIFT
I might just try this one, but feel like I’m going to break the way Cardboard is set up and then have to do a lot of customization anyway…)
Never mind. I think I was just being too lazy (need more coffee!)
I believe the solution (in case anybody else is looking to do this) is to add this to the GazeInput.cs script that Cardboard uses [might need to do a few other tweaks, but the general idea is this should work]:
void HandleSelection()
{
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 + GazeTimeInSeconds;
}
// if we have a handler and it's time to click, do it now
if (currentLookAtHandler != null &&
(mode == Mode.Gaze && Time.realtimeSinceStartup > currentLookAtHandlerClickTime) ||
(mode == Mode.Click && Input.GetButtonDown(ClickInputName)))
{
ExecuteEvents.ExecuteHierarchy(currentLookAtHandler, pointerEventData, ExecuteEvents.pointerClickHandler);
currentLookAtHandlerClickTime = float.MaxValue;
}
}
else
{
currentLookAtHandler = null;
}
}
NOTE: I also plan to animate the cursor to show a “countdown” (or, really, a “count-up” circular timer)… in my past project, I did this using a shader that allowed for cutoff based on alpha, and creating the icon as one with a radial alpha gradient. I’m not sure if this is the best method on mobile, however, or if it would give better efficiency to use an animated sprite.
Hello,
I’m trying to implement the time gaze function on the VR Sample package, but i can’t figure it out.
On the example, we have to click for triggering “fire1” and the radial will fill up.
How can i do the same but only when you look at the selection ?
I tried to fake input fire1 but i really don’t think it’s the good solution for this.
I think it’s somewhere near the VRInput.cs …
Thanks for any help on this,
I will continue to search for it and if i find it i will tell you!
Hello,
I used your solution and it works almost perfectly, thanks! I just can’t figure out why the timer resets with a delay. It needs around 1-2 seconds to reset the selection radial. This way, sometimes it starts my action too fast
private void HandleOver ()
{
// The user is now looking at the bar.
m_GazeOver = true;
// Play the clip appropriate for when the user starts looking at the bar.
m_Audio.clip = m_OnOverClip;
m_Audio.Play();
HandleDown(); // Here autoclick
}
Some help here. I have been trying to use the Gaze input in cardboard instead of the mouse click… Can someone help me convert the click input into gaze with some code or something…
I am having issues with the selection method for gaze input. I can get the collision object to verify that it has been selected but then I have to click it with my mouse or any other device I cant get the timed selection module to integrate.