Unity开发HTC vive 一、手柄按钮
来源:互联网 发布:淘宝买花苗 编辑:程序博客网 时间:2024/05/16 15:36
认识下vive的手柄
请看下图
手柄两个一对,分左右,开发的时候也是分左右的。每个上面有一个pad和4个按钮。简单说明下:
- 开关、系统菜单按钮:只有这个按钮不可以编程(默认),用来打开手柄,其实没用关的功能。在游戏中按下该按钮是调出系统默认的菜单,用来关闭,切换游戏用的。
- menu按钮:默认用来打开游戏菜单。
- grip按钮:用的最少的按钮,每个手柄上虽然有两个,但是是相同的。
- trigger按钮:扳机按钮,用的最多,可以有力度。
- pad:触摸屏+鼠标的功能,可触摸,可点击。
SDK下载
需要两个插件:
SteamVR Plugin和
Vive Input Utility
商城地址如下,都是免费的,下载后导入
https://www.assetstore.Unity3D.com/cn/#!/content/32647
https://www.assetstore.unity3d.com/cn/#!/content/64219
程序开发之综述
- using HTC.UnityPlugin.Vive;
using HTC.UnityPlugin.Vive;
每个按钮包括pad都有GetPress、GetPressDown、GetPressUp三种方法,用HandRole枚举来确定左右手柄,用ControllerButton枚举来确定是哪个按钮。
对于按钮,GetPressDown是按下时触发,GetPressUp是放开时触发,以上两个是个事件,GetPress是按住时一直返回ture,算是一个状态。
对于pad,有两种:
当ControllerButton.Pad时,和按钮相同。
当ControllerButton.PadTouch时,GetPressDown是接触时触发,GetPressUp是离开时触发,GetPress是接触时一直返回的状态。
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using HTC.UnityPlugin.Vive;
- public class viveLearn : MonoBehaviour {
- // Update is called once per frame
- void Update () {
- if (ViveInput.GetPress (HandRole.RightHand, ControllerButton.Menu)) {
- Debug.Log (”menu press”);
- }
- if (ViveInput.GetPressUp (HandRole.RightHand, ControllerButton.Menu)) {
- Debug.Log (”menu press up”);
- }
- if (ViveInput.GetPressDown (HandRole.RightHand, ControllerButton.Menu)) {
- Debug.Log (”menu press down”);
- }
- }
- }
using System.Collections;using System.Collections.Generic;using UnityEngine;using HTC.UnityPlugin.Vive;public class viveLearn : MonoBehaviour { // Update is called once per frame void Update () { if (ViveInput.GetPress (HandRole.RightHand, ControllerButton.Menu)) { Debug.Log ("menu press"); } if (ViveInput.GetPressUp (HandRole.RightHand, ControllerButton.Menu)) { Debug.Log ("menu press up"); } if (ViveInput.GetPressDown (HandRole.RightHand, ControllerButton.Menu)) { Debug.Log ("menu press down"); } }}
除了上面的方法,还可以通过回掉的方式实现
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using HTC.UnityPlugin.Vive;
- public class viveLearn : MonoBehaviour {
- private void Awake(){
- ViveInput.AddPress (HandRole.LeftHand, ControllerButton.Menu, OnMenuPress);
- }
- private void OnDestory(){
- ViveInput.RemovePress (HandRole.LeftHand, ControllerButton.Menu, OnMenuPress);
- }
- private void OnMenuPress(){
- Debug.Log (”menu press”);
- }
- }
using System.Collections;using System.Collections.Generic;using UnityEngine;using HTC.UnityPlugin.Vive;public class viveLearn : MonoBehaviour { private void Awake(){ ViveInput.AddPress (HandRole.LeftHand, ControllerButton.Menu, OnMenuPress); } private void OnDestory(){ ViveInput.RemovePress (HandRole.LeftHand, ControllerButton.Menu, OnMenuPress); } private void OnMenuPress(){ Debug.Log ("menu press"); }}
Trigger按钮开发
Trigger有模拟值,从0到1,没按的时候是0,全部按下是1。可以通过GetTriggerValue方法获得。
- ViveInput.GetTriggerValue (HandRole.LeftHand, false);
ViveInput.GetTriggerValue (HandRole.LeftHand, false);
Trigger按钮,对应有三种,Trigger,HairTrigger,FullTrigger。
当TriggerValue在0.1到0.2时,对应HairTrigger,当TriggerValue超过0.5时对应Trigger,当TriggerValue=1时,对应FullTrigger。
可以简单理解为,轻按=HairTriiger,中度按=Trigger,全部按下=FullTrigger。
Pad开发
pad做那么大,当然除了可以按,还可以返回位置信息。用GetPadAxis方法即可。
- ViveInput.GetPadAxis (HandRole.LeftHand, false);
ViveInput.GetPadAxis (HandRole.LeftHand, false);触碰位置信息如下图
此外,对应pad,又有接触、按下的两组方法。其中,Axis是坐标位置,Delta是最后一帧移动位置,Vector是移动的向量。
- ViveInput.GetPadTouchAxis (HandRole.LeftHand, false);
- ViveInput.GetPadTouchDelta (HandRole.LeftHand, false);
- ViveInput.GetPadTouchVector (HandRole.LeftHand, false);
- ViveInput.GetPadPressAxis (HandRole.LeftHand, false);
- ViveInput.GetPadPressDelta (HandRole.LeftHand, false);
- ViveInput.GetPadPressVector (HandRole.LeftHand, false);
ViveInput.GetPadTouchAxis (HandRole.LeftHand, false); ViveInput.GetPadTouchDelta (HandRole.LeftHand, false); ViveInput.GetPadTouchVector (HandRole.LeftHand, false); ViveInput.GetPadPressAxis (HandRole.LeftHand, false); ViveInput.GetPadPressDelta (HandRole.LeftHand, false); ViveInput.GetPadPressVector (HandRole.LeftHand, false);
- Unity开发HTC vive 一、手柄按钮
- Unity开发HTC vive 一、手柄按钮
- Unity开发HTC vive 一、手柄按钮
- unity开发 HTC vive手柄控制 手柄上各个按钮的点击事件
- Unity的Htc Vive手柄按钮检测(转)
- Unity +HTC VIVE 虚拟现实开发— 手柄控制
- Unity +HTC VIVE 虚拟现实开发— 手柄震动
- (Unity)HTC ViVe 之手柄震动
- Unity开发HTC VIVE
- Unity3d开发 HTC vive手柄控制 手柄上各个按钮的点击事件
- HTC vive开发:关于手柄按键
- HTC vive开发:关于手柄按键
- HTC Vive开发笔记之手柄震动
- Unity开发HTC vive 入门
- unity中检测不到HTC vive手柄的解决方案
- HTC Vive VR房产项目开发一(手柄提示+户型图)
- Htc Vive Sdk(OpenVR),Unity3d 开发,手柄射线
- HTC vive开发:关于手柄按键对接控制
- 设计模式-工厂模式
- java六大设计模式
- 使用asp.net core的启动篇
- MySQL注入技巧性研究
- unity学习笔记(一)
- Unity开发HTC vive 一、手柄按钮
- StateMachine 的简单使用
- 一个有意思的算法
- Java 反射
- oracle基本操作
- python: numpy --函数 tile用法
- Ubuntu与Windows7双系统环境搭建
- GCC C语言处理hooks实现
- eclipse中开发NDK以及环境搭建(一)