Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouse click on VRTK UI Canvas along with UIPointer possible? #1554

Open
pampas93 opened this issue Oct 10, 2017 · 13 comments
Open

Mouse click on VRTK UI Canvas along with UIPointer possible? #1554

pampas93 opened this issue Oct 10, 2017 · 13 comments
Projects

Comments

@pampas93
Copy link

Using the vrtk UI canvas, is there a feature or property that could be used where, Both Oculus touch's pointer and the mouse interaction can be used?

For now, The canvas is made World space and interactable with Oculus UI pointer. How can make the UI elements be interactable with mouse as well?

@bddckr
Copy link
Collaborator

bddckr commented Oct 11, 2017

Unity's UI system only allows using one input module and ours is just a VR input module.
I think we only allow mouse stuff on non-VRTK_UICanvases, so if you want to use one with both you're out of luck.

Maybe there's an easy way to support mice by just emitting pointer events from the mouse to our UI stuff? I don't really know 😄

@dantman
Copy link

dantman commented Oct 16, 2017

A more important question is what the purpose of supporting both is. Is it because you want to click in the editor game window, click in the spectator view, or because you want to also support playing your game with a mouse and keyboard?

@bddckr
Copy link
Collaborator

bddckr commented Oct 17, 2017

Any of the screen space canvases should work for mouse interaction. The example scenes use the SDK Setup Switcher prefab that offers such a GUI which isn't visible in the HMD.

@pampas93
Copy link
Author

@dantman I was going for an application in which the UI could be controlled by the user using the Oculus, and the user outside the oculus (in front of the system).

@pampas93
Copy link
Author

@bddckr Mouse interaction works fine when I make the canvas mode to Screen space. But this disrupts the control from the Oculus touch.

@Minicholo
Copy link

I have a similar situation where I have a non-VR camera (rendered on monitor) that needs the ability to click on VRTK_UICanvas items alongside someone using the Vive.

@bddckr
Copy link
Collaborator

bddckr commented Nov 3, 2017

As I said: Unity's event system only allows one active input module. If you find time to basically merge our VR one with theirs (which does mouse, keyboard and touch) go for it!

@FreakinKat

This comment has been minimized.

@bddckr

This comment has been minimized.

@FreakinKat

This comment has been minimized.

@Eraile
Copy link

Eraile commented Jan 15, 2018

Hello guys, I was confronted to that need. It's extremely simple to solve (i dont know which version of VRTK i have but one of the latest).

Just make VRTK_UICanvas inherit GraphicRaycaster (probably there is also an extra change to do).
And override the necessary functions (OnEnable, OnDisable, OnDestroy) with base calls.

public class VRTK_UICanvas : GraphicRaycaster
{
[...]
        protected override void OnEnable()
        {
            base.OnEnable();
            SetupCanvas();
        }

        protected override void OnDisable()
        {
            base.OnDisable();
            RemoveCanvas();
        }

        protected override void OnDestroy()
        {
            base.OnDestroy();
            RemoveCanvas();
        }
[...]

Cheers!

@pampas93
Copy link
Author

pampas93 commented Feb 2, 2018

@Eraile I tried your solution, but my mouse clicks still have no response on the menu.

@thestonefox thestonefox added this to To do in VRTK May 9, 2019
@aignermax
Copy link

aignermax commented Jan 17, 2020

Hi there,

you can simply reactivate the GraphicsRayCasters via Script.
Just add this script to the "VR Simulator" GameObject that is beneath "[VRTK_SDKSetups], and use the Simulator as main camera.

Works like a charm.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ReactivateRayCaster : MonoBehaviour
{
void Start()
{
StartCoroutine(EnableAllRaycasters());
}

public IEnumerator EnableAllRaycasters()
{
    yield return new WaitForEndOfFrame();
    yield return new WaitForSeconds(0.1f);
    // find all canvases in scene
    GraphicRaycaster[] Raycasters = FindObjectsOfType<GraphicRaycaster>();
    foreach (GraphicRaycaster g in Raycasters)
    {
        g.enabled = true;
    }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
VRTK
  
To do
Development

No branches or pull requests

8 participants