Unity HTC VIVE VR一体机基础操作

  • VIVE Focus 触摸板
  • VIVE Focus 按键操作
  • VIVE Focus 碰撞触发
  • VIVE Focus 动态输出
  • VIVE Focus 指针操作

老规矩,直接上代码:

VIVE Focus 触摸板

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using wvr;public class EventType_ZH : MonoBehaviour
{WVR_Event_t _Event = new WVR_Event_t();//系统事件//检测手柄WaveVR_Controller.EDeviceType curFocusControllerType = WaveVR_Controller.EDeviceType.Dominant;Transform _WaveVR;private void Start(){_WaveVR = GameObject.Find("WaveVR").transform;}private void Update(){switch (_Event.common.type){//当手指在触摸板上从左向右滑过时触发case WVR_EventType.WVR_EventType_LeftToRightSwipe://向右走_WaveVR.position = Vector3.right * Time.deltaTime;break;//当手指在触摸板上从右往左滑过时触发case WVR_EventType.WVR_EventType_RightToLeftSwipe://向左走_WaveVR.position = Vector3.left * Time.deltaTime;break;//当手纸在触摸板上从上到下滑过时触发case WVR_EventType.WVR_EventType_UpToDownSwipe://向后走_WaveVR.position = Vector3.back * Time.deltaTime;break;//当手纸在触摸板上从下到上滑过时触发case WVR_EventType.WVR_EventType_DownToUpSwipe://向前走_WaveVR.position = Vector3.forward * Time.deltaTime;break;default:break;}//触摸板if (WaveVR_Controller.Input(curFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_DPad_Up)){//向前走_WaveVR.position = Vector3.forward * Time.deltaTime;print("触摸板 上");}if (WaveVR_Controller.Input(curFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_DPad_Down)){//向后走_WaveVR.position = Vector3.back * Time.deltaTime;print("触摸板 下");}if (WaveVR_Controller.Input(curFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_DPad_Left)){//向左走_WaveVR.position = Vector3.left * Time.deltaTime;print("触摸板 左");}if (WaveVR_Controller.Input(curFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_DPad_Right)){//向右走_WaveVR.position = Vector3.right * Time.deltaTime;print("触摸板 右");}}
}

VIVE Focus 按键操作

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Video;
using WaveVR_Log;
using wvr;
using UnityEngine.UI;public class Button_Color : MonoBehaviour/*, IPointerHoverHandler, IPointerExitHandler,IPointerEnterHandler,IPointerClickHandler*/
{Material _Mater;            //材质VideoPlayer _Video;         //视频bool _bColor;               //材质布尔public Text _ButtonText;//检测手柄WaveVR_Controller.EDeviceType curFocusControllerType = WaveVR_Controller.EDeviceType.Dominant;//检测按键方式//WVR_DeviceType curFocusControllerType = WVR_DeviceType.WVR_DeviceType_Controller_Right;void Start(){_Mater = GetComponent<Renderer>().material;_Video = GameObject.Find("Video").GetComponent<VideoPlayer>();}void Update(){//如果按下了手柄的 Trigger 键if (WaveVR_Controller.Input(curFocusControllerType).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Trigger)){//ColorTrigger();print("扳机键");_ButtonText.text = "扳机键";}//如果按下了手柄的 菜单键else if (WaveVR_Controller.Input(curFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_Menu)){print("菜单键");_ButtonText.text = "菜单键";}//如果按下了手柄的 握柄键else if (WaveVR_Controller.Input(curFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_Grip)){print("握柄键");_ButtonText.text = "握柄键";}//如果按下了手柄的 系统键else if (WaveVR_Controller.Input(curFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_System)){print("系统键");_ButtonText.text = "系统键";}//如果按下了手柄的 触摸键else if (WaveVR_Controller.Input(curFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_Touchpad)){print("触摸键");// _ButtonText.text = "触摸键";}//如果持续按下了手柄的 Trigger键else if (WaveVR_Controller.Input(curFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_Volume_Down)){print("持续按下Trigger键");_ButtonText.text = "持续按下Trigger键";// WaveVR_Controller.Input(curFocusControllerType).}//如果持续松开了手柄的 Trigger键else if (WaveVR_Controller.Input(curFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_Volume_Up)){print("持续松开Trigger键");_ButtonText.text = "持续松开Trigger键";}//触摸板else if (WaveVR_Controller.Input(curFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_DPad_Up)){print("触摸板 上");_ButtonText.text = "触摸板 上";}else if (WaveVR_Controller.Input(curFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_DPad_Down)){print("触摸板 下");_ButtonText.text = "触摸板 下";}else if (WaveVR_Controller.Input(curFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_DPad_Left)){print("触摸板 左");_ButtonText.text = "触摸板 左";}else if (WaveVR_Controller.Input(curFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_DPad_Right)){print("触摸板 右");_ButtonText.text = "触摸板 右";}else if (WaveVR_Controller.Input(curFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_Digital_Trigger)){print("Digital_Trigger");_ButtonText.text = "Digital_Trigger";}else if (WaveVR_Controller.Input(curFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_Enter)){print("Enter");_ButtonText.text = "Enter";}else if (WaveVR_Controller.Input(curFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_Thumbstick)){print("Thumbstick");_ButtonText.text = "Thumbstick";}else if (WaveVR_Controller.Input(curFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Max)){print("Max");_ButtonText.text = "Max";}}public void OnClick_Button(){if (Input.GetMouseButtonDown(0)){_bColor = !_bColor;RaycastHit _Hit;if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out _Hit)){if (_Hit.collider.name == "Cube"){if (_bColor){_Mater.color = Color.green;}else{_Mater.color = Color.yellow;}}}}}//颜色替换public void ColorTrigger(){_bColor = !_bColor;if (_bColor){_Mater.color = Color.green;}else{_Mater.color = Color.yellow;}}//视频播放public void VideoPlayOnClick(){_Video.Play();}//视频停止public void VideoStopOnClick(){_Video.Stop();}
}

VIVE Focus 碰撞触发

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HTC.UnityPlugin.ColliderEvent;public class VIVE_Collider_ZH : MonoBehaviour, IColliderEventHoverEnterHandler,IColliderEventHoverExitHandler,IColliderEventPressEnterHandler,IColliderEventPressUpHandler,IColliderEventDragUpdateHandler,IColliderEventAxisChangedHandler{public void OnColliderEventAxisChanged(ColliderAxisEventData eventData){//当触发器进入物体//如果是触摸板if (eventData.axis==ColliderAxisEventData.InputAxis.Scroll2D){//打印触摸版数值print(eventData.axis);}//如果是Trigger 键else if (eventData.axis == ColliderAxisEventData.InputAxis.Trigger1D){//打印 Trigger 值print(eventData.axis);}}public void OnColliderEventDragUpdate(ColliderButtonEventData eventData){//当触发器进入物体 并开始移动的时候触发print("移动");}public void OnColliderEventHoverEnter(ColliderHoverEventData eventData){//当触发器进入物体时 触发print("进入");}public void OnColliderEventHoverExit(ColliderHoverEventData eventData){//当触发器退出物体时 触发print("退出");}public void OnColliderEventPressEnter(ColliderButtonEventData eventData){//进入物体并按下按钮print("按下");}public void OnColliderEventPressUp(ColliderButtonEventData eventData){//进入物体并松开按钮print("松开");}
}

VIVE Focus 动态输出

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HTC.UnityPlugin.Vive;
using UnityEngine.UI;public class VIVE_Input_ZH : MonoBehaviour
{[Header("按钮")]public Text _InputText;[Header("Value_Trigger")]public Text _InputValue;[Header("Value_Pad_X")]public Text _InpuPad_X;[Header("Value_Pad_Y")]public Text _InputPad_Y;void Update(){if (ViveInput.GetPressDownEx(HandRole.RightHand, ControllerButton.Trigger)){//右手扳机键_InputText.text = "右手扳机键";}if (ViveInput.GetPressDownEx(HandRole.RightHand, ControllerButton.Menu)){//菜单键_InputText.text = "菜单键";}if (ViveInput.GetPressDownEx(HandRole.RightHand, ControllerButton.Grip)){//握柄键_InputText.text = "握柄键";}if (ViveInput.GetPressDownEx(HandRole.RightHand, ControllerButton.DPadUp)){//触摸板 上_InputText.text = "触摸板 上";}if (ViveInput.GetPressDownEx(HandRole.RightHand, ControllerButton.DPadDown)){//触摸板 上_InputText.text = "触摸板 下";}if (ViveInput.GetPressDownEx(HandRole.RightHand, ControllerButton.DPadLeft)){//触摸板 上_InputText.text = "触摸板 左";}if (ViveInput.GetPressDownEx(HandRole.RightHand, ControllerButton.DPadRight)){//触摸板 上_InputText.text = "触摸板 右";}// 扳机程度_InputValue.text = ViveInput.GetAxisEx(HandRole.RightHand, ControllerAxis.Trigger).ToString();// 触摸板 X轴_InpuPad_X.text = ViveInput.GetAxisEx(HandRole.RightHand, ControllerAxis.PadX).ToString();// 触摸板 Y轴_InputPad_Y.text = ViveInput.GetAxisEx(HandRole.RightHand, ControllerAxis.PadY).ToString();}
}

VIVE Focus 指针操作

/// <summary>
/// 射线接口实现
/// </summary>
public class VIVE_Collider_ZH : MonoBehaviour, IPointerHoverHandler,IPointerEnterHandler,IPointerClickHandler,IPointerExitHandler
{//指针悬停public void OnPointerHover(PointerEventData eventData){//GameObject.Find("Video").transform.localScale = Vector3.zero;}//指针退出public void OnPointerExit(PointerEventData eventData){//GameObject.Find("Video").transform.localScale = Vector3.one;}//指针进入public void OnPointerEnter(PointerEventData eventData){//GameObject.Find("Video").SetActive(false);}//指针触发public void OnPointerClick(PointerEventData eventData){//按下扳机键 惯用手(默认右手)if (WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.Dominant).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Trigger)){print("右手确认!");}//按下扳机键 非惯用手(默认左手)if (WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.NonDominant).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Trigger)){print("左手确认!");}}
}

暂时先这样吧,如果有时间的话就会更新,如果实在看不明白就留言,看到我会回复的。

路长远兮,与君共勉。

Unity HTC VIVE VR一体机基础操作相关推荐

  1. 基于unity+HTC VIVE的室内漫游交互(教你如何“无代码”VR交互)

    简单粗暴,一个插件让你无代码实现VR交互 开发环境steamVR2.0+unity2017.1.0f1 steamVR2.0下载地址 一.总体目标 Unity+HTC VIVE 开发: 1.场景漫游+ ...

  2. HTC vive VR设备软硬件安装+运行unity开发的VR程序

    总结在HTC vive VR开发过程中的HTC vive的安装调试 1.首先确保电脑的配置满足要求: 进入官网,测试电脑是否满足要求 链接:https://www.vive.com/us/produc ...

  3. 使用Unity+HTC VIVE做VR时如何创建用户体验较强的菜单

    该文章仅作为本人工作过程中的开发笔记,难免有不严谨不深刻的地方,适合刚入门Unity+HTC VIVE新手制作VR菜单时作为参考,望大神勿喷. 在使用Unity+HTC VIVE制作VR游戏或者严肃游 ...

  4. Htc Vive VR 手势识别插件教程 1.1 版本(附1.0版本教程PDF)

    VR手势识别插件教程1.1.1版本 VR手势识别插件教程1.1.1版本内容提纲 Htc Vive VR手势识别插件教程1.1.1版本.................................. ...

  5. HTC VIVE VR眼镜的介绍以及初始化设置

    硬件设备介绍 使用的硬件设备:HTC VIVE 或 HTC VIVE Pro 1.认识一下HTC VIVE VR头盔上的主要部件: A 是基站(定位器) x 2(发射激光定位头显与手柄控制器) B 是 ...

  6. VIVE开发基础(A、快速入门篇)(Yanlz+HTC+VIVE+VR+AR+MR+XR+SteamVR+CameraRig+LightHouse+HeadSet+Teleport+立钻哥哥+)

    <HTC_VIVE开发基础> 版本 作者 参与者 完成日期 备注 HTC_VIVE_V01_1.0 严立钻 2018.08.23 <HTC_VIVE开发基础>发布说明: +++ ...

  7. 眼球追踪技术 Unity+ HTC vive Pro + DroolonF1 (一)

    本篇博客主要讲开发前的配置,如安装配置问题. 开发前需要准备: 1.DroolonF1设备 2.SR_Runtime驱动 3.SRinipal SDK 4.Unity开发引擎 建议2017.3版本以上 ...

  8. HTC推出VR一体机与开放平台,汪丛青表示每个行业一开始就爆发是不现实的...

    HTC携Vive Focus一体机与Vive Wave VR平台,引领打造中国VR优质生态. 今天的HTC大会上,汪丛青没有穿上他那件和VIVE同色系的标志性蓝色西服,让人颇为意外. 11月14日,H ...

  9. Unity程序在VR一体机(Android)上卡死(闪退)后怎么办?——用adb查看android上某Unity app的debug信息

    一.之前面临的困境 Unity的程序build到android一体机后,仿佛进入了一个黑箱子,你既看不到脚本的debug报错信息,也看不到任务管理器里的内存和CPU使用情况?如果黑屏.闪屏.花屏怎么办 ...

最新文章

  1. 【Gradle】借助gradle的ProductFlavor实现多App间代码库复用
  2. Windows 7防火墙配置FTP相关
  3. POJ 2151 Check the difficulty of problems (概率dp)
  4. 一起谈.NET技术,VS2010测试功能之旅:编码的UI测试(2)-操作动作的录制原理(下)...
  5. 深度学习之卷积神经网络(12)深度残差网络
  6. SAP License:雾里看花系列——换种思维来看待SAP
  7. 中国凝胶密封高效空气过滤器行业市场供需与战略研究报告
  8. 代码理解(2009.11.20)
  9. 利用k-means算法实现图像自动色彩量化
  10. MVC HtmlHelper listbox用法
  11. “互联网+”时代,漫谈影响用户体验的X因素
  12. Java--继承(三)
  13. flask:小项目(医生与病人)
  14. linux终端怎么设置monaco,ubuntu16.04安装monaco字体
  15. 《C语言》2022山西专升本C语言知识点
  16. 【3dmax千千问】初学3dmax插件神器第16课|VRAY学习教程|疯狂模渲大师怎么使用VRAY渲染器?食住玩3dmax入门到精通进阶教程
  17. 搜狗推送工具-搜狗批量提交软件
  18. java 分层处理解耦_后端分层架构如何解耦?
  19. 苹果电脑macos Monterey 12.5(21G72)dmg原版引导版镜像下载
  20. stm32第一章cortex-M3处理器概述

热门文章

  1. 大三如何备战考研?需要注意些什么?
  2. Live:主流技术构建即时聊天室演示应用,直播源码
  3. 数字图像处理实验(三)|图像增强{归一化直方图imhist(f)/numel(f)、直方图均衡化histeq、生成线性空间滤波fspecial、中值滤波medfilt2}(附matlab实验代码截图)
  4. 英语学习详细笔记(十四)附加问句
  5. 给 Java 学习者的超全教程整理
  6. android 数据库锁的问题
  7. 怎么升级linux的内核版本,升级linux内核版本
  8. U盘防毒,我有绝招。。。
  9. c语言中用FILE类型的使用
  10. python 常用镜像源