简体   繁体   中英

XR Interaction Toolkit - Hover event on UI Elements with XRRayInteractor

I'm trying to make a VR game on Oculus Quest with the XR Interaction Toolkit and I would like to configure an haptic event when the user is hovering a UI element. The problem is that the haptic event works when I'm hovering a XRGrabInteractable or a TeleportationArea with the XRRayInteractor but not on a canvas. Even the simple hover event (OnHoverUI on the picture) isn't working on the canvas. It's really weird because I can interact with the UI elements (buttons, sliders, ...).

Here are the parameters of my XRRayInteractor : XRRayInteractor parameters

I already found a solution working without those parameters but it's really annoying. First, I needed to access the controllers (right and left hands). Then, I added a "Event Trigger" component to every single UI element on which I want a haptic feedback. Those triggers have a "Pointer Enter" event calling the "OnHoverUI" function.

void Start()
{
    var inputDevices = new List<InputDevice>();
    InputDevices.GetDevices(inputDevices);
    foreach (var device in inputDevices)
    {
        if (device.role.ToString() == "LeftHanded")
        {
             leftHand = device;
        }
        else if (device.role.ToString() == "RightHanded")
        {
            rightHand = device;
        }
    }
}

public void OnHoverUI()
{
    if (leftMenuMode) leftHand.SendHapticImpulse(0, 1f, 0.01f);
    else if (rightMenuMode) rightHand.SendHapticImpulse(0, 1f, 0.01f);
}

I really would like to use the parameters of the XRRayInteractor but they don't work with the UI.

Does someone have an idea why ?

An old question but I found a simple workaround when trying to get "is the XRInteractorRay valid" using XRInteractorLineVisual.reticle.activeInHierarchy .

First create two empty GameObjects in the hierarchy, rename them to "leftLineVisual" and "rightLineVisual" respectively and disable both GameObjects. On each of the XRInteractorLineVisual scripts (on each XR controller), set the reticle to the corrisponding GameObject in the hierarchy.

You can then get the status of the XR Ray with XRInteractorLineVisual.reticle.activeInHierarchy for example

[SerializeField] XRInteractorLineVisual leftLineVisual;
[SerializeField] XRInteractorLineVisual rightLineVisual;

void Update() {
    if (rightLineVisual.reticle.activeInHierarchy || leftLineVisual.reticle.activeInHierarchy)
    {
        Debug.Log("One of the pointers is active");
    }
    else
    {
        Debug.Log("Both of the pointers are disabled");
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM