当前位置:网站首页>【ViveFocus使用WaveVR插件获取手柄操作事件】
【ViveFocus使用WaveVR插件获取手柄操作事件】
2022-06-13 07:01:00 【灬凤年】
ViveFocus使用WaveVR插件获取手柄操作事件
此文的诞生
入职新公司,接手旧项目,程序猿不可避免的麻烦。不巧,在下正是被一个旧VR项目卡在了怎么获取手柄事件上。网上找了很多资料,基本没有,可能是因为ViveFocus这款单手柄的设备销量不太行的原因吧。今天就把方法告诉大家,省的大家跟我走一样的弯路。
单手柄设备
一、插件必备WaveVR
这个WaveVR插件啊,Unity商城就有免费版,直接下载导入即可,在这里提一下的原因是,有很多人喜欢荡网盘资源,我想说的是像这种常用插件,大家最好还是先去Unity商城和PakageManager下找找有没有,有的话就用Unity自身的毕竟版本最好,最优。
(你要说你的Unity版本不支持那么高的版本,我想说那就另当别论了,只是建议)
下面开始正题
二、场景中放置必要的预制件
第一步,场景中放置必要的预制件这五个缺一不可。
WaveVR—确保VR视角
ControllerLoader—VR基础控制器(比如惯用手调整等)
InputModuleManager—射线检测控制管理器
ButtonManager—手柄按钮生效管理
WaveVRButtons—手柄按钮配置列表
三、代码获取手柄交互事件
做完上面的准备工作,正题这就来了:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using wvr;//命名空间必须的
public class GamePanel : MonoBehaviour
{
Text showText;
CanvasGroup group;
private void Awake()
{
//因为最终打包为安卓给眼镜使用,所以普通的打印不够看,
//最好生成一个Text组件,交互按钮之后,将内容显示在里面
showText = transform.Find("ShowText").GetComponent<Text>();
//控制UI界面显隐
group = transform.GetComponent<CanvasGroup>();
}
void Start()
{
}
private void Update()
{
//判断场景中有没有放入预制体,避免没放时报错
if (WaveVR_ButtonManager.Instance == null)
return;
//大圆盘按下
bool pressedTouchpad = WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.Dominant).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Touchpad);
if (pressedTouchpad)
{
showText.text = "按下了Touchpad!!!";
group.alpha = 1;
}
//扳手键按下
bool pressedTrigger = WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.Dominant).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Trigger);
if (pressedTrigger)
{
showText.text = "按下了Trigger!!!";
group.alpha = 0;
}
//圆盘上按下
bool pressedUp = WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.Dominant).GetPressDown(WVR_InputId.WVR_InputId_Alias1_DPad_Up);
if (pressedUp)
{
showText.text = "按下了Up!!!";
}
//中间大圆键按下,带横线那个
bool pressedMenu = WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.Dominant).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Menu);
if (pressedMenu)
{
showText.text = "按下了Menu!!!";
}
//音量键+按下
bool pressedVolume_Up = WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.Dominant).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Volume_Up);
if (pressedVolume_Up)
{
showText.text = "按下了Volume_Up!!!";
}
}
}
结束语
Binggo~,就这么简单!!!
原创不易,分享开发过程中的坑!!!
若对您有一定的帮助,欢迎点赞!!!
有疑问欢迎看留言!!!
天南地北兄妹情,给个赞啊行不行!!!
边栏推荐
- 个人js学习笔记
- [weak transient signal detection] matlab simulation of SVM detection method for weak transient signal under chaotic background
- Soup side (8)
- 105. constructing binary trees from preorder and inorder traversal sequences
- 通过函数seaborn.cubehelix_palette生成顺序调色板
- The biggest highlight of wwdc2022: metalfx
- Recently, the popular social e-commerce marketing model, blind box e-commerce, how beautiful every second is accurately drained
- 【转】FPGA面试题
- Is it safe to open an account online in Hangzhou?
- Ansible PlayBook的中清单变量优先级分析及清单变量如何分离总结
猜你喜欢
Byte (nine)
Gold jewelry enterprise operation mode, beautiful tiantians business solution
Try to use renderdoc to view the shader code of UE
[system analysis and design] college student association management system
What is the new business model of Taishan crowdfunding in 2022?
简单了解C语言基本语
Tikv key performance parameters and optimization
[cloud native | kubernetes] kubernetes configuration
智能金融再升级,景联文科技提供数据采集标注服务
Why is the new e-commerce outlet mode so popular? What is the specific mode?
随机推荐
髋关节MR详细图谱(转载)
2022-06-12:在N*N的正方形棋盘中,有N*N个棋子,那么每个格子正好可以拥有一个棋子。 但是现在有些棋子聚集到一个格子上了,比如: 2 0 3 0 1 0 3 0 0 如上的二维数组代表,一
What is the new business model of Taishan crowdfunding in 2022?
Monotone stack top31 of interview must brush algorithm top101
汇编语言基础:寄存器和寻址方式
[RS-422 and RS-485] RS-422 and RS-485 serial interface standard
景联文科技提供语音数据采集标注服务
SDN基本概述
Tidb statistics
Differences between SQL and NoSQL of mongodb series
Continuous management design
RT-Thread 模拟器 simulator LVGL控件:switch 开关按钮控件
Tidb index optimization
Will the chain 2+1 model be a new business outlet and a popular Internet e-commerce market?
What does my financial product mean in clearing?
景联文科技:数据采集标注行业现状及解决方案
【转】FPGA面试题
Yolov5 analysis | parameters and performance indicators
数字时代进化论
ML:机器学习模型的稳定性分析简介、常见的解决方法之详细攻略