Detecting hovering on button event on Oculus Quest (Unity3D)

。_饼干妹妹 提交于 2020-03-23 07:57:10

问题


Stack:

  • Oculus Quest
  • Unity 2019.3
  • Oculus VR Integration
  • macOS Catilina

I have a Unity scene with a VR interface composed by a Canvas (World Space coordinates) and two buttons. The canvas has attached an OVR Raycaster objects which uses a laser pointer. Overall it works well, but when I try to intercept the event produced by hovering the laser pointer on the button, I can get only the click event.

I'm using the following script (attached to the button):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class VRButton : MonoBehaviour, IPointerEnterHandler, IPointerClickHandler, ISelectHandler
{
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }

    public void OnPointerEnter(PointerEventData eventData)
    {
        Debug.Log("Enter!");
        transform.localScale *= 1.2f;
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        Debug.Log("Exit!");
        transform.localScale /= 1.2f;
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        Debug.Log("Clicked!");
    }
}

The strange thing is that both OnPointerEnter and OnPointerClick get called when I point the button with the laser and click. Just hovering the doesn't trigger any event (nor OnPointerExit or OnPointerEnter).

This is my ADB log:

03-15 22:59:53.085 13339 13355 I Unity   : Clicked!
03-15 22:59:53.085 13339 13355 I Unity   : UnityEngine.Logger:Log(LogType, Object)
03-15 22:59:53.085 13339 13355 I Unity   : UnityEngine.EventSystems.EventFunction`1:Invoke(T1, BaseEventData)
03-15 22:59:53.085 13339 13355 I Unity   : UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
03-15 22:59:53.085 13339 13355 I Unity   : UnityEngine.EventSystems.OVRInputModule:ProcessMousePress(MouseButtonEventData)
03-15 22:59:53.085 13339 13355 I Unity   : UnityEngine.EventSystems.OVRInputModule:ProcessMouseEvent(MouseState)
03-15 22:59:53.085 13339 13355 I Unity   :  
03-15 22:59:53.085 13339 13355 I Unity   : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
03-15 22:59:53.085 13339 13355 I Unity   : 
03-15 22:59:53.085 13339 13355 I Unity   : Enter!
03-15 22:59:53.085 13339 13355 I Unity   : UnityEngine.Logger:Log(LogType, Object)
03-15 22:59:53.085 13339 13355 I Unity   : VRButton:OnPointerEnter(PointerEventData)
03-15 22:59:53.085 13339 13355 I Unity   : UnityEngine.EventSystems.EventFunction`1:Invoke(T1, BaseEventData)
03-15 22:59:53.085 13339 13355 I Unity   : UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
03-15 22:59:53.085 13339 13355 I Unity   : UnityEngine.EventSystems.BaseInputModule:HandlePointerExitAndEnter(PointerEventData, GameObject)
03-15 22:59:53.085 13339 13355 I Unity   : UnityEngine.EventSystems.OVRInputModule:ProcessMousePress(MouseButtonEventData)
03-15 22:59:53.085 13339 13355 I Unity   : UnityEngine.EventSystems.OVRInputModule:ProcessMouseEvent(MouseState)

How can I fix it?

来源:https://stackoverflow.com/questions/60698832/detecting-hovering-on-button-event-on-oculus-quest-unity3d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!