十一、pico+Unity交互开发教程——手指触控交互(Poke Interaction)

一、XR Poke Interactor

  1. 交互包括发起交互的对象(Interactor)和可被交互的对象(Interactable)。XR Interaction Toolkit提供了XR Poke Interactor脚本用于实现Poke功能。
  2. LeftHand ControllerRightHand Controller``物体下创建名为Poke Interactor的空物体,并添加XR Poke Interactor脚本。
  3. 设置XR Poke Interactor中的Attach Transform,在手部模型下创建代表交互点的子物体(如Poke Point),并将其拖至XR Poke Interactor脚本中的Attach Transform处。
  4. 若手部有其他Interactor,可将Poke Interactor添加到LeftHand ControllerRightHand Controller上的XR Interaction Group中,确保一个Interactor起作用时其他Interactor暂时失效。

二、与UI进行触控交互

  1. 添加Tracked Device Graphic RaycasterXR UI Input Module让UI可被交互,在Canvas上添加Tracked Device Graphic Raycaster脚本;

  2. 在EventSystem上添加XR UI Input Module脚本。

三、与物体进行交互

  1. XR Simple Interactable

    • 用红色方块代表可交互物体,添加XR Simple Interactable脚本。
    • XR Simple InteractableInteractable Events中添加事件,如在Select Entered时让方块材质变成黄色,在Hover Exited时让方块材质变回红色。这个在前面学过
    • 由于XR Simple Interactable默认会被其他Interactor触发,为避免手靠近方块时按下手柄Grip键触发Select Entered事件,可将XR Poke Interactor的Interaction Layer Mask和方块挂载的XR Simple Interactable的Interaction Layer Mask进行设置。经测试,在XRI 2.3.2版本下,可将XR Simple Interactable的Interaction Layer Mask单独设置一个层级(如"Poke"),XR Poke InteractorInteraction Layer Mask设置为Everything,使Poke Interactor单独与方块进行交互。 这个也学过;
  2. XR Poke Filter

    • 运行程序时若无法触发Poke,是因为XR Poke Interactor默认勾选了Require Poke Filter,此时能发生Poke交互的物体必须拥有XR Poke Filter组件。
    • 在方块上添加XR Poke Filter组件,可调整Poke Configuration参数,如将Poke Direction设为Negative Y,即手指从上往下触碰方块时可触发Poke

通过以上步骤,我们成功实现了Unity VR中的手指触控交互功能,为VR体验增添了更多自然和直观的交互方式。

相关推荐
空中海4 小时前
第二篇:Unity中级阶段(核心开发能力)
unity·游戏引擎
DaLiangChen10 小时前
Unity 实用工具:动态绘制物体边界包围盒(支持屏幕固定线宽)
unity·游戏引擎
张老师带你学11 小时前
Unity 食物 农产品相关
科技·游戏·unity·游戏引擎·模型
mxwin11 小时前
Unity Custom Interpolators与半透明阴影的原理与实战
unity·游戏引擎·shader
晴夏。11 小时前
UE5第三人称模板实现及相关引擎源码分析
unity·ue5·游戏引擎·ue
HAPPY酷11 小时前
解决 Unreal Engine 编译报错 MSB4018:三个核心排查方向
游戏引擎·虚幻
晴夏。15 小时前
UE原生MovementBase实现分析
游戏引擎·ue·3c
天人合一peng16 小时前
Unity工程发布hololens需安装, MRTK安装
unity·游戏引擎·hololens
weixin_4093831217 小时前
godot 调用class方法得用实例 不能用脚本引用
游戏引擎·godot
风酥糖17 小时前
Godot游戏练习01-第32节-国际化
游戏·游戏引擎·godot