VRTK3.3.0-002获取手柄事件
2024-08-29 14:01:22
1、首先创建VRScripts空物体,用来存放脚本,在其下创建Right空物体并添加VRTK_ControllerEvents脚本
2、Right作为右手手柄,拖拽到[VRTK_SDKManager]的RightController上
3丶在Right上新建脚本RightController,通过得到VRTK_ControllerEvents组件注册方法,就可以监听到按下手柄哪些键了
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VRTK;// 引用VRTK命名空间 public class RightController: MonoBehaviour
{
private VRTK_ControllerEvents controllerEvents;
private void Awake()
{
controllerEvents = GetComponent<VRTK_ControllerEvents>();
// 输入+=后按Tab键后自动补全方法
controllerEvents.TouchpadPressed += ControllerEvents_TouchpadPressed;
controllerEvents.TouchpadReleased += ControllerEvents_TouchpadReleased;
controllerEvents.GripPressed += ControllerEvents_GripPressed;
} private void ControllerEvents_GripPressed(object sender, ControllerInteractionEventArgs e)
{
Debug.Log("抓取键按下");
} private void ControllerEvents_TouchpadReleased(object sender, ControllerInteractionEventArgs e)
{
Debug.Log("圆盘键按释放");
} private void ControllerEvents_TouchpadPressed(object sender, ControllerInteractionEventArgs e)
{
Debug.Log("圆盘键按下");
}
}
还有许多方法这里不逐条列出,大家自行查看VRTK_ControllerEvents脚本
4丶注意:只要涉及到操作手柄,就必须要添加VRTK_ControllerEvents脚本
最新文章
- [LeetCode] Insertion Sort List 链表插入排序
- cannot simultaneously fetch multiple bags
- Java基础(42):Java中主类中定义方法加static和不加static的区别(前者可以省略类名直接在主方法调用,后者必须先实例化后用实例调用)
- python 基础学习(字典对象,set对象)
- python之---类和实例
- 转:Git_Windows 系统下Git安装图解
- android的intent打开系统程序
- [ACM] POJ 3273 Monthly Expense (二分解决最小化最大值)
- 使用elk+redis搭建nginx日志分析平台(转)
- Android 动画的分类
- recycleView 使用指南1
- Collections模块下的Counter
- C#一句话判断两个List<;T>;是否相等
- 多个子域名前端网站调用同一个webAPI时session混用问题
- C#-多态(十二)
- [JOI2017/2018]美術展
- Python3字典
- POJ - 3122 Pie(二分)
- Java中使用FileputStream导致中文乱码问题的修改方案
- 在Spark上运行TopK程序