Search Unity

Timed Gaze Input selection trigger for Cardboard?

Discussion in 'AR/VR (XR) Discussion' started by guru20, Dec 13, 2015.

  1. guru20

    guru20

    Joined:
    Jul 30, 2013
    Posts:
    239
    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: http://talesfromtherift.com/vr-gaze-input/

    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...)
     
    roger-wang likes this.
  2. guru20

    guru20

    Joined:
    Jul 30, 2013
    Posts:
    239
    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]:
    Code (CSharp):
    1. void HandleSelection()
    2.     {
    3.         if (pointerEventData.pointerEnter != null)
    4.         {
    5.             // if the ui receiver has changed, reset the gaze delay timer
    6.             GameObject handler = ExecuteEvents.GetEventHandler<IPointerClickHandler>(pointerEventData.pointerEnter);
    7.             if (currentLookAtHandler != handler)
    8.             {
    9.                 currentLookAtHandler = handler;
    10.                 currentLookAtHandlerClickTime = Time.realtimeSinceStartup + GazeTimeInSeconds;
    11.             }
    12.          
    13.             // if we have a handler and it's time to click, do it now
    14.             if (currentLookAtHandler != null &&
    15.                 (mode == Mode.Gaze && Time.realtimeSinceStartup > currentLookAtHandlerClickTime) ||
    16.                 (mode == Mode.Click && Input.GetButtonDown(ClickInputName)))
    17.             {
    18.                 ExecuteEvents.ExecuteHierarchy(currentLookAtHandler, pointerEventData, ExecuteEvents.pointerClickHandler);
    19.                 currentLookAtHandlerClickTime = float.MaxValue;
    20.             }
    21.         }
    22.         else
    23.         {
    24.             currentLookAtHandler = null;
    25.         }
    26.     }
    27.  


    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.
     
  3. SniperEvan

    SniperEvan

    Joined:
    Mar 3, 2013
    Posts:
    161
    The VR samples that Unity released on the asset store give an example of this too. The code is pretty slick.
     
  4. guru20

    guru20

    Joined:
    Jul 30, 2013
    Posts:
    239
    I heard that Unity had some VR examples, but couldn't find them... will take another look
     
  5. SniperEvan

    SniperEvan

    Joined:
    Mar 3, 2013
    Posts:
    161
  6. guru20

    guru20

    Joined:
    Jul 30, 2013
    Posts:
    239
    Yeah, I found em... thanks!
     
  7. sPiz

    sPiz

    Joined:
    Jun 15, 2013
    Posts:
    4
    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!
     
  8. sPiz

    sPiz

    Joined:
    Jun 15, 2013
    Posts:
    4
    Hello Again,
    Ok i find it, to do it simply,
    Put in SelectionRadial.cs "HandleDown() like this :

    Code (CSharp):
    1.         public void Show()
    2.         {
    3.             m_Selection.gameObject.SetActive(true);
    4.             m_IsSelectionRadialActive = true;
    5.             HandleDown();
    6.         }
    7.  
     
    estebanjavierst likes this.
  9. couba

    couba

    Joined:
    Mar 14, 2016
    Posts:
    1
    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
     
    Jmeij and gibtmirdas like this.
  10. TechnicalArtist

    TechnicalArtist

    Joined:
    Jul 9, 2012
    Posts:
    736
    Hi,

    Anyone try gaze for slider?
     
    lsiguis likes this.
  11. kmiccio

    kmiccio

    Joined:
    Jun 6, 2016
    Posts:
    1
    Is the same...

    Locate :
    VRSampleScenes/Scripts/Utils/SelectionSlider.cs

    And replace ... line 177 to 186

    Code (CSharp):
    1.  
    2. private void HandleOver ()
    3.         {
    4.             // The user is now looking at the bar.
    5.             m_GazeOver = true;
    6.  
    7.             // Play the clip appropriate for when the user starts looking at the bar.
    8.             m_Audio.clip = m_OnOverClip;
    9.             m_Audio.Play();
    10.             HandleDown(); // Here autoclick
    11.         }
    12.  
     
  12. TechnicalArtist

    TechnicalArtist

    Joined:
    Jul 9, 2012
    Posts:
    736
    Thanks for reply
     
  13. Annelysu

    Annelysu

    Joined:
    Mar 2, 2016
    Posts:
    3
    Works perfeclty, thanks you !
     
  14. Selzier

    Selzier

    Joined:
    Sep 23, 2014
    Posts:
    652
     
    ashishsfb likes this.
  15. Selzier

    Selzier

    Joined:
    Sep 23, 2014
    Posts:
    652
     
  16. Shreenath1322

    Shreenath1322

    Joined:
    Apr 7, 2016
    Posts:
    7
    Hi everyone,

    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...
     
  17. Annelysu

    Annelysu

    Joined:
    Mar 2, 2016
    Posts:
    3

    Hey man, did you figure out how to fix the bug of the reset of the selection radial ? It tooks me 1-2 sec also ...

    Thanks you !
     
  18. steve-o616

    steve-o616

    Joined:
    Sep 27, 2016
    Posts:
    2
    Same here, anyone manage to figure out a work around for this yet? Thanks
     
  19. Shadowpark

    Shadowpark

    Joined:
    Dec 1, 2016
    Posts:
    3
    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.
     
  20. Shadowpark

    Shadowpark

    Joined:
    Dec 1, 2016
    Posts:
    3
    Did you get it to work?
     
  21. Herpalism

    Herpalism

    Joined:
    Nov 12, 2014
    Posts:
    2
    Aestial likes this.
  22. gibtmirdas

    gibtmirdas

    Joined:
    Jan 22, 2017
    Posts:
    1
    I managed to reset the timer properly when you look away from the object and look at it back quickly.
    I called HandleUp() in the function Hide() and changed the instruction sequence inside it, in order to reset the fillAmount first.
    It now looks like this:
    Code (CSharp):
    1. public void Hide() {
    2.   m_Selection.fillAmount = 0f;
    3.   HandleUp();
    4.   m_Selection.gameObject.SetActive(false);
    5.   m_IsSelectionRadialActive = false;
    6. }
     
    Ga2Z likes this.
  23. kainathanif28

    kainathanif28

    Joined:
    Oct 24, 2018
    Posts:
    1
    hey did you solve it?