HTC Vive Cosmos开发——手柄按钮事件

8 篇文章 1 订阅
4 篇文章 0 订阅

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 ");
    }
}

  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ToDoNothing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值