我有一个 ScrollView ,其中包含几个按钮作为内容面板下的子元素。层次结构如下所示:
我在附加到 ScrollView 的脚本上实现了这样的 OVRTouchpad.TouchHandler
事件:
void Start()
{
#if OVR && !UNITY_EDITOR
OVRTouchpad.Create();
OVRTouchpad.TouchHandler += HandleTouchHandler;
#endif
}
void HandleTouchHandler (object sender, System.EventArgs e)
{
OVRTouchpad.TouchArgs touchArgs = (OVRTouchpad.TouchArgs)e;
if(touchArgs.TouchType == OVRTouchpad.TouchEvent.Left || touchArgs.TouchType == OVRTouchpad.TouchEvent.Up)
{
// Code to scroll UP for swipe in directions LEFT/UP
}
else if(touchArgs.TouchType == OVRTouchpad.TouchEvent.Right || touchArgs.TouchType == OVRTouchpad.TouchEvent.Down)
{
// Code to scroll DOWN for swipe in directions RIGHT/DOWN
}
}
问题:
因为我正在使用 OVR Input Muodule ,即使我尝试滑动,它也会处理 Tap
输入。因此,每次我在凝视按钮( ScrollView 的子项)时向任何方向滑动。单击按钮将我带到其他菜单。我不确定这是否是 Gear VR 输入系统的预期行为。正如我在 Oculus Home 应用程序(以及商店中的其他应用程序)中看到的那样,它只会滚动而不会触发对子元素的点击。
如果检测到滑动,有什么方法可以防止点击/点击?
非常感谢任何形式的帮助。
最佳答案
您是否尝试过先插入一个 IF 语句来处理单次触发?
if(touchArgs.TouchType == OVRTouchpad.TouchEvent.SingleTap)
{
//TODO: Nest IF statements here checking conditions which indicate swipe instead of tap. If nothing further detected, process single tap.
//Otherwise continue with swipe direction handling.
}
但据说使用本教程中提到的 VRInput 脚本可能是您最好的选择,因为它也可以处理带有方向输入的滑动。
https://unity3d.com/learn/tutorials/topics/virtual-reality/interaction-vr
片段:
public event Action<SwipeDirection> OnSwipe; // Called every frame passing in the swipe, including if there is no swipe.
关于c# - 如何处理 Oculus Gear VR 触摸板上的滑动以避免点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39371951/