Search Unity

OnMouseEnter() does not work with Oculus VR mode!

Discussion in 'AR/VR (XR) Discussion' started by Arowx, Mar 26, 2015.

  1. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Just noticed that the OnMouseEnter() functions don't work with an OculusRift camera rig, is there a work around for this?

    Should it still work as there are still cameras viewing a 3D scene.

    Also how do other developers handle mouse input in VR?
     
  2. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
  3. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    I don't know the answer to your first question. Comments here are regarding the second question:

    At the end of that thread in the link you posted is a video of what I ended up with that you might have seen.

    What I ended up doing there was having two objects to help me get the 3D mouse cursor working. I forget the function name, but I use the mouse delta rather than the actual mouse screen position to move my second, invisible mouse cursor around a plane hanging out in space behind the GUI somewhere. I then raycast from the camera to that invisible point on the plane and if it hits a GUI canvas, I recompute the position of the cursor to be on that plane.

    Moving the GUI around with the mouse and keeping it locked to the canvas like is done in the video took a little bit of trickery to make work like that. Depending on what you're doing it may not even be necessary. I just wanted a way to move my GUI out of the way and let the user customize it so I don't have to come up with some "one size fits all" static position.
     
  4. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    Regarding the first question: To get the GUI to respond to events, I used the modified script in that thread. In the end it seemed to be all about calling ExecuteEvents with ExecuteEvents.pointerExitHandler (or enter) and those types of things. As far as I've been able to figure, those are what tell the 4.6 GUI system that the mouse just left or entered a mouse button and so forth.

    The general idea is to use colliders. My buttons all have box colliders on them and my mouse GUI has a little invisible sphere collider on the very tip of it. When they collide (and maybe when they stop colliding too, I'd have to check again) I then send the ExecuteEvents.pointerExitHandler and those types of things. That basically tricks the Unity UI into thinking the normal mouse cursor has actually done that action even though in my case it's locked and invisible. I.e., there's no Windows mouse cursor there at all, basically. It's all done with the 3D objects instead.

    I got it from Ralph Barbagallo's article here:
    http://ralphbarbagallo.com/2014/08/...ursors-for-world-space-canvases-in-unity-4-6/

    His code that he links to in the above article is here:
    https://gist.github.com/flarb/052467190b84657f10d2

    I had to modify and extend it a bit for my purposes, but it outlined the general idea to get started. I couldn't have done it without Ralph's article. I'm very grateful that he shared it!