Search Unity

  1. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

[Gear VR] Updating to 5.4 caused custom gaze input module for uGUI to stop working in build.

Discussion in 'AR/VR (XR) Discussion' started by Boredman1234, Jul 29, 2016.

  1. Boredman1234

    Boredman1234

    Joined:
    Sep 17, 2013
    Posts:
    16
    I am using the following input module that i got from here to used uGUI for the GearVR.

    Code (CSharp):
    1. // Gaze Input Module by Peter Koch <peterept@gmail.com>
    2. using UnityEngine;
    3. using UnityEngine.EventSystems;
    4. using System.Collections.Generic;
    5.  
    6. // To use:
    7. // 1. Drag onto your EventSystem game object.
    8. // 2. Disable any other Input Modules (eg: StandaloneInputModule & TouchInputModule) as they will fight over selections.
    9. // 3. Make sure your Canvas is in world space and has a GraphicRaycaster (should by default).
    10. // 4. If you have multiple cameras then make sure to drag your VR (center eye) camera into the canvas.
    11. public class GazeInputModule : PointerInputModule
    12. {
    13.     public enum Mode { Click = 0, Gaze };
    14.     public Mode mode;
    15.  
    16.     [Header("Click Settings")]
    17.     public string ClickInputName = "Submit";
    18.     [Header("Gaze Settings")]
    19.     public float GazeTimeInSeconds = 2f;
    20.  
    21.     public RaycastResult CurrentRaycast;
    22.  
    23.     private PointerEventData pointerEventData;
    24.     private GameObject currentLookAtHandler;
    25.     private float currentLookAtHandlerClickTime;
    26.  
    27.     public override void Process()
    28.     {
    29.         HandleLook();
    30.         HandleSelection();
    31.     }
    32.  
    33.     void HandleLook()
    34.     {
    35.         if (pointerEventData == null)
    36.         {
    37.             pointerEventData = new PointerEventData(eventSystem);
    38.         }
    39.         // fake a pointer always being at the center of the screen
    40.         pointerEventData.position = new Vector2(Screen.width/2, Screen.height/2);
    41.         pointerEventData.delta = Vector2.zero;
    42.         List<RaycastResult> raycastResults = new List<RaycastResult>();
    43.         eventSystem.RaycastAll(pointerEventData, raycastResults);
    44.         CurrentRaycast = pointerEventData.pointerCurrentRaycast = FindFirstRaycast(raycastResults);
    45.         ProcessMove(pointerEventData);
    46.     }
    47.    
    48.     void HandleSelection()
    49.     {
    50.         if (pointerEventData.pointerEnter != null)
    51.         {
    52.             // if the ui receiver has changed, reset the gaze delay timer
    53.             GameObject handler = ExecuteEvents.GetEventHandler<IPointerClickHandler>(pointerEventData.pointerEnter);
    54.             if (currentLookAtHandler != handler)
    55.             {
    56.                 currentLookAtHandler = handler;
    57.                 currentLookAtHandlerClickTime = Time.realtimeSinceStartup + GazeTimeInSeconds;
    58.             }
    59.            
    60.             // if we have a handler and it's time to click, do it now
    61.             if (currentLookAtHandler != null &&
    62.                 (mode == Mode.Gaze && Time.realtimeSinceStartup > currentLookAtHandlerClickTime) ||
    63.                 (mode == Mode.Click && Input.GetButtonDown(ClickInputName)))
    64.             {
    65.                 ExecuteEvents.ExecuteHierarchy(currentLookAtHandler, pointerEventData, ExecuteEvents.pointerClickHandler);
    66.                 currentLookAtHandlerClickTime = float.MaxValue;
    67.             }
    68.         }
    69.         else
    70.         {
    71.             currentLookAtHandler = null;
    72.         }
    73.     }
    74.  
    75.  
    76. }
    Everything was working fine until I updated to 5.4 today. Now the input module works in the editor, but not in the build. Anyone know what I can do to fix it? Thanks.
     
  2. JDMulti

    JDMulti

    Joined:
    Jan 4, 2012
    Posts:
    385
    It works for me in the editor, but with an offset. Aiming at buttons doesn't work, aiming above them works fine. I don't know if this is a bug or someone has changed.
     
  3. JDMulti

    JDMulti

    Joined:
    Jan 4, 2012
    Posts:
    385
    After some searching and I came across your post in google, I saw 2 pages later this solution and it works:"

    https://community.unity.com/t5/5-4-...r-VR-after-upgrading-to-5-4-beta/td-p/2639154

    Took me a while to find out tbh, didn't knew some things had changed.

    Code (CSharp):
    1. // fake a pointer always being at the center of the screen
    2. pointerEventData.position = new Vector2(UnityEngine.VR.VRSettings.eyeTextureWidth/2, UnityEngine.VR.VRSettings.eyeTextureHeight / 2);
     
  4. Selzier

    Selzier

    Joined:
    Sep 23, 2014
    Posts:
    644
  5. Boredman1234

    Boredman1234

    Joined:
    Sep 17, 2013
    Posts:
    16
    Awesome. Thanks for the help!
     
unityunity