1.环境配置
htc vive cosmos的环境配置比较简单,在HTC VIVE官网下载VIVEPORT客户端即可:网址:viveport
2.手柄按键事件(unity+VRTK)
(1)将VRTK和Steam VR导入,steam vr版本不能太新,按VRTK官网推荐的即可,我用的steam vr版本是1.2.3,unity版本为2019.4.8f1。官网传送:VRTK
(2)其次就是,在Player Setting里面,需要把OpenVR放在最上面,把None去掉。
(3)手柄的按键对应可以在VRTK的事件机制中试出来,方法也很简单,在手柄的映射中添加一个脚本。
(4)代码也很简单,如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VRTK;
public class TriggerButtonTest : MonoBehaviour
{
private VRTK_ControllerEvents controllerEvents;
void Start()
{
controllerEvents = GetComponent<VRTK_ControllerEvents>();
controllerEvents.TriggerPressed += DoTriggerPressed;
//ButtonOnePressed对应 Cosmos手柄为X键
controllerEvents.ButtonOnePressed += ButtonOnePress;
//ButtonTwoPressed对应 Cosmos手柄为Y键
controllerEvents.ButtonTwoPressed += ButtonTwoPress;
//GripPressed对应 Cosmos手柄为Grip键
controllerEvents.GripPressed += GripPress;
//TouchpadPressed对应 Cosmos手柄为Grip键
controllerEvents.TouchpadPressed += TouchpadPress;
}
// Update is called once per frame
void Update()
{
}
private void DoTriggerPressed(object sender, ControllerInteractionEventArgs e)
{
Debug.Log("Trigger Press");
}
private void ButtonOnePress(object sender, ControllerInteractionEventArgs e)
{
Debug.Log("ButtonOnePress ");
}
private void ButtonTwoPress(object sender, ControllerInteractionEventArgs e)
{
Debug.Log("ButtonTwoPress");
}
private void StartMenuPress(object sender, ControllerInteractionEventArgs e)
{
Debug.Log("StartMenuPress ");
}
private void GripPress(object sender, ControllerInteractionEventArgs e)
{
Debug.Log("GripPress ");
}
private void TouchpadPress(object sender, ControllerInteractionEventArgs e)
{
Debug.Log("TouchpadPress ");
}
}