一体机VR交互的实现
A) 3Dof手柄适配(P1/P1 Pro)
1、正常导入DPVRunity插件(请使用0.7.0或以上版本);
2、将菜单栏DPVR->Settings中,Peripheral Support选项设为Flip;
3、将DpnCameraRig.prefab会在运行时自动生成手柄相关的prefab,包含代码和模型。
如何获取手柄信息:
1、如果要获取手柄的姿态和按键信息,可以参考Daydream手柄,在DpnDaydreamController.cs脚本上使用相关属性来获取,属性说明请参考脚本注释。相比Daydream手柄,我们的手柄添加了trigger按键,删除了VolumeUp和VolumeDown两个按键,App键被修改为Back键,Home键保持不变。其中Back键和>Home键有系统默认行为,无需应用特殊处理;
当前系统默认实现如下:
Back:功能同系统返回键;
Home:短按功能同android手机的Home键,长按recenter校准;
2、手柄默认自带射线碰撞系统,若将菜单栏->DPVR->Settings中Use DPVRPointer选项勾选,此时将开启大朋的碰撞系统(默认行为)。若不勾选该选项,用户可使用自定义的碰撞检测逻辑;
3、如果将菜单栏->DPVR->Settings中Peripheral Support选项设为None,则应用默认使用头控不会加载3dof手柄模型;
4、大朋Unity插件0.7.3b及之后的版本中,手柄支持左右手切换,设置接口为DpnDaydreamController.interactiveHand { set, get }。其中0代表右手,1代表左手。(需配合最新image使用);
5、UI互动的逻辑DPVRunity 0.7.6及之后版本请使用DpnEventSystem替换EventSystem的方式(请参看《我的第一个VR应用(Unity)》第7点内容)或者用DpnStandaloneInputModule替换EventSystem下的StandaloneInputModule组件的方式(请参看《现有Unity3D游戏的VR移植教程》第9点内容)的实现示例。
B) 头控触摸板(M2、M2 Pro、P1、P2)
如果将菜单栏->DPVR->Settings中Peripheral Support选项设为None,则应用默认使用头控。一体机右侧有一个触摸板,该触摸板响应的是标准TouchPad和Mouse的消息,它只支持单点触摸。
在Unity3D中,可以使用Input.touchCount来判断是否有Touch。然后通过Input.GetTouch(0)获得这个Touch的信息,包括位置、大小等。
此外触摸板还响应了Mouse消息,所以也可以通过Input.GetMouseButton(0)得知是否有Touch,而Input.mousePosition则是当前Touch的位置。
下面的脚本挂在一个Text下面就可以输出这些消息。
using UnityEngine; using UnityEngine.UI; using System.Collections; public class TouchPad : MonoBehaviour { Text txt; // Use this for initialization void Start() { txt = GetComponent<Text>(); } // Update is called once per frame void Update() { string msg = "touch: "; if(Input.touchCount > 0) { Touch tch = Input.GetTouch(0); msg += tch.position.x + "," + tch.position.y + "," + tch.deltaPosition.x + "," + tch.deltaPosition.y + "," + tch.radius + "\n"; } else { msg += "none\n"; } Vector3 mouse_position = Input.mousePosition; bool btn0 = Input.GetMouseButton(0); msg += btn0.ToString() + " " + mouse_position.x + "," + mouse_position.y + "," + mouse_position.z + "\n"; txt.text = msg; } } |