Unity 3D基于steamvr unity插件包进行开发,怎么判断手柄与其他物体的接触

基于Unity3D的手势识别程序设计方法_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
基于Unity3D的手势识别程序设计方法
上传于||暂无简介
阅读已结束,如果下载本文需要使用0下载券
想免费下载更多文档?
定制HR最喜欢的简历
你可能喜欢Unity的HTC VIVE SDK研究(手柄按键功能的研究,比较详细)
Unity的HTC VIVE SDK研究(手柄按键功能的研究,比较详细)
想交流的朋友我们可以微博互粉,我的微博黑石铸造厂厂长&,缺粉丝啊
。。。。。求粉求粉
研究了几天htc vive的接口,总算是把基本的按键功能研究出来了,这里分享一下,一来当做笔记,二来也希望对大家有所帮助。
如何导入Steam_VR那个包什么的我就不说了,网上有几个前辈已经教了,蛮牛论坛啥的上面都有,这里只把比较详细的按键功能分享一下,不知啥高端的东西,也算一段时间劳动成果啦,所以转载的帮我留个名写个转,谢谢啦。
个人感觉手柄上开始比较难搞明白的就是那个圆盘键,这个键是一个以中心为(0,0)点的直角坐标系,四个端长度都是1,可接收触摸和按压两种事件,大体就是下图这个意思(手绘水平略渣,见谅见谅),触摸touch或按压press会通过GetAxis方法返回一个坐标系中的点,可以判断你按在哪里,触发不同的事件,可以根据角度或各种方法来切分按键为n个按钮(就像切蛋糕一样)
这里用的是C#脚本 ,直接上代码了,我个人写注释比较话唠,适合新手看:
using&UnityE&&using&System.C&&//检测手柄功能的脚本&这个脚本挂到手柄上(controler(right)和controler(left))上&&public&class&ButtonTouchAction&:&MonoBehaviour&{&&&&&&//手柄&&&&&&SteamVR_TrackedObject&trackdeO&&&&&&&&void&Awake()&{&&&&&&&&&&//获取手柄上的这个组件&&&&&&&&&&trackdeObjec&=&GetComponent&SteamVR_TrackedObject&();&&&&&&}&&&&&&//&Use&this&for&initialization&&&&&&void&Start&()&{&&&&&&&&&}&&&&&&void&FixedUpdate()&&&&&&{&&&//获取手柄输入&&&&&&&&&&var&device&=&SteamVR_Controller.Input((int)trackdeObjec.index);&&&&&&&&&&//以下是api中复制出来的按键列表&&&&&&&&&&/*&&&&&&&public&class&ButtonMask&&&&&&&&&&&&{&&&&&&&&&&&&&&&&public&const&ulong&System&=&(1ul&&&&(int)EVRButtonId.k_EButton_System);&//&reserved&&&&&&&&&&&&&&&&public&const&ulong&ApplicationMenu&=&(1ul&&&&(int)EVRButtonId.k_EButton_ApplicationMenu);&&&&&&&&&&&&&&&&public&const&ulong&Grip&=&(1ul&&&&(int)EVRButtonId.k_EButton_Grip);&&&&&&&&&&&&&&&&public&const&ulong&Axis0&=&(1ul&&&&(int)EVRButtonId.k_EButton_Axis0);&&&&&&&&&&&&&&&&public&const&ulong&Axis1&=&(1ul&&&&(int)EVRButtonId.k_EButton_Axis1);&&&&&&&&&&&&&&&&public&const&ulong&Axis2&=&(1ul&&&&(int)EVRButtonId.k_EButton_Axis2);&&&&&&&&&&&&&&&&public&const&ulong&Axis3&=&(1ul&&&&(int)EVRButtonId.k_EButton_Axis3);&&&&&&&&&&&&&&&&public&const&ulong&Axis4&=&(1ul&&&&(int)EVRButtonId.k_EButton_Axis4);&&&&&&&&&&&&&&&&public&const&ulong&Touchpad&=&(1ul&&&&(int)EVRButtonId.k_EButton_SteamVR_Touchpad);&&&&&&&&&&&&&&&&public&const&ulong&Trigger&=&(1ul&&&&(int)EVRButtonId.k_EButton_SteamVR_Trigger);&&&&&&&&&&&&}&&&&&&&&&&&&*/&&&&&&&&&&&&&&&//同样是三种按键方式,以后不做赘述&&&&&&&&&&if&(device.GetTouch(SteamVR_Controller.ButtonMask.Trigger))&{&&&&&&&&&&&&&&Debug.Log("按了&“trigger”&“扳机键”");&&&&&&&&&&&&&&&&&&&&&&&&&&&//右手震动&&&&&&&&&&&&&&//拉弓类似操作应该就是按住trigger(扳机)gettouch时持续调用震动方法模拟弓弦绷紧的感觉。&&&&&&&&&&&&&&var&deviceIndex2&=&SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost);&&&&&&&&&&&&&&SteamVR_Controller.Input(deviceIndex2).TriggerHapticPulse(500);&&&&&&&&&&&&}&&&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger))&&&&&&&&&&{&&&Debug.Log("按下了&“trigger”&“扳机键”");&&&&&&&&&&&&}&&&&&&&&&&if&(device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger))&{&&&&&&&&&&&&&&Debug.Log("松开了&“trigger”&“扳机键”");&&&&&&&&&&&&&&&&&&&&&&&&&&//左手震动&&&&&&&&&&&&&&var&deviceIndex&=&SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost);&&&&&&&&&&&&&&SteamVR_Controller.Input(deviceIndex).TriggerHapticPulse(3000);&&&&&&&&&&&&&&&&&&&&&&&&&&&//右手震动&&&&&&&&&&&&&&var&deviceIndex1&=&SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost);&&&&&&&&&&&&&&SteamVR_Controller.Input(deviceIndex1).TriggerHapticPulse(3000);&&&&&&&&&&}&&&&&&&&&&&&//这三种也能检测到&后面不做赘述&&&&&&&&&&if(device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))&{&&&&&&&&&&&&&&Debug.Log("用press按下了&“trigger”&“扳机键”");&&&&&&&&&&}&&&&&&&&&&if&(device.GetPress(SteamVR_Controller.ButtonMask.Trigger))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("用press按了&“trigger”&“扳机键”");&&&&&&&&&&}&&&&&&&&&&if&(device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("用press松开了&“trigger”&“扳机键”");&&&&&&&&&&}&&&&&&&&&&&&//system键&圆盘下面那个键&&&&&&&&&&&//&reserved&为Steam系统保留,用来调出Steam系统菜单&因此貌似自己加的功能没啥用&&&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.System))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("按下了&“system”&“系统按钮/Steam”");&&&&&&&&&&}&&&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.System))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("用press按下了&“System”&“系统按钮/Steam”");&&&&&&&&&&}&&&&&&&&&&&&//ApplicationMenu键&带菜单标志的那个按键(在方向圆盘上面)&&&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.ApplicationMenu))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("按下了&“ApplicationMenu”&“菜单键”");&&&&&&&&&&}&&&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("用press按下了&“ApplicationMenu”&“菜单键”");&&&&&&&&&&}&&&&&&&&&&&&//Grip键&两侧的键&(vive雇佣兵游戏中的换弹键),每个手柄左右各一功能相同,同一手柄两个键是一个键。&&&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Grip))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("按下了&“Grip”&“&”");&&&&&&&&&&}&&&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Grip))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("用press按下了&“Grip”&“&”");&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&&&&&&//Axis0键&与圆盘有交互&与圆盘有关&&&&&&&&&&//触摸触发&&&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis0))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("按下了&“Axis0”&“方向&”");&&&&&&&&&&}&&&&&&&&&&//按动触发&&&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis0))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("用press按下了&“Axis0”&“方向&”");&&&&&&&&&&}&&&&&&&&&&&&//Axis1键&&目前未发现按键位置&&&&&&&&&&//触摸触发&&&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis1))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("按下了&“Axis1”&“&”");&&&&&&&&&&}&&&&&&&&&&//按动触发&&&&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis1))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("用press按下了&“Axis1”&“&”");&&&&&&&&&&}&&&&&&&&&&&&//Axis2键&目前未发现按键位置&&&&&&&&&&//触摸触发&&&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis2))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("按下了&“Axis2”&“&”");&&&&&&&&&&}&&&&&&&&&&//按动触发&&&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis2))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("用press按下了&“Axis2”&“&”");&&&&&&&&&&}&&&&&&&&&&&&//Axis3键&&未目前未发现按键位置&&&&&&&&&&//触摸触发&&&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis3))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("按下了&“Axis3”&“&”");&&&&&&&&&&}&&&&&&&&&&//按动触发&&&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis3))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("用press按下了&“Axis3”&“&”");&&&&&&&&&&}&&&&&&&&&&&&//Axis4键&&目前未发现按键位置&&&&&&&&&&//触摸触发&&&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis4))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("按下了&“Axis4”&“&”");&&&&&&&&&&}&&&&&&&&&&//按动触发&&&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis4))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("用press按下了&“Axis4”&“&”");&&&&&&&&&&}&&&&&pre&name="code"&class="csharp"&&&&&&&&//方向圆盘:&&&&&&&&&&//这里开始区分了press检测与touch检测的不同之处,圆盘可以触摸,顾名思义,touch检测的是触摸,press检测的是按动&pre&name="code"&class="csharp"&&//Axis0键&与圆盘有交互&与圆盘有关&&&&&&&&&&//触摸触发&&&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis0))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("按下了&“Axis0”&“方向&”");&&&&&&&&&&}&&&&&&&&&&//按动触发&&&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis0))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("用press按下了&“Axis0”&“方向&”");&&&&&&&&&&}&&&&&&&&&&&&//Axis1键&&目前未发现按键位置&&&&&&&&&&//触摸触发&&&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis1))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("按下了&“Axis1”&“&”");&&&&&&&&&&}&&&&&&&&&&//按动触发&&&&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis1))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("用press按下了&“Axis1”&“&”");&&&&&&&&&&}&&&&&&&&&&&&//Axis2键&目前未发现按键位置&&&&&&&&&&//触摸触发&&&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis2))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("按下了&“Axis2”&“&”");&&&&&&&&&&}&&&&&&&&&&//按动触发&&&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis2))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("用press按下了&“Axis2”&“&”");&&&&&&&&&&}&&&&&&&&&&&&//Axis3键&&未目前未发现按键位置&&&&&&&&&&//触摸触发&&&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis3))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("按下了&“Axis3”&“&”");&&&&&&&&&&}&&&&&&&&&&//按动触发&&&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis3))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("用press按下了&“Axis3”&“&”");&&&&&&&&&&}&&&&&&&&&&&&//Axis4键&&目前未发现按键位置&&&&&&&&&&//触摸触发&&&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis4))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("按下了&“Axis4”&“&”");&&&&&&&&&&}&&&&&&&&&&//按动触发&&&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis4))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("用press按下了&“Axis4”&“&”");&&&&&&&&&&}&&&&&&&&&&&&&&//ATouchpad键&圆盘交互&&&&&&&&&&//触摸触发&&&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad))&&&&&&&&&&{&&&&&&&&&&&&&&&&&Debug.Log("按下了&“Touchpad”&“&”");&&&&&&&&&&&&&&&&&&&&&&&&&&&&//方法返回一个坐标&接触圆盘位置&&&&&&&&&&&&&&Vector2&cc&=&device.GetAxis();&&&&&&&&&&&&&&Debug.Log(cc);&&&&&&&&&&&&&&//&例子:圆盘分成上下左右&&&&&&&&&&&&&&float&jiaodu&=&VectorAngle(new&Vector2(1,&0),&cc);&&&&&&&&&&&&&&Debug.Log(jiaodu);&&&&&&&&&&&&&&//下&&&&&&&&&&&&&&if&(jiaodu&&&45&&&&jiaodu&&&135)&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&Debug.Log("下");&&&&&&&&&&&&&&}&&&&&&&&&&&&&&//上&&&&&&&&&&&&&&if&(jiaodu&&&-45&&&&jiaodu&&&-135)&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&Debug.Log("上");&&&&&&&&&&&&&&}&&&&&&&&&&&&&&//左&&&&&&&&&&&&&&if&((jiaodu&&&180&&&&jiaodu&&&135)&||&(jiaodu&&&-135&&&&jiaodu&&&-180))&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&Debug.Log("左");&&&&&&&&&&&&&&}&&&&&&&&&&&&&&//右&&&&&&&&&&&&&&if&((jiaodu&&&0&&&&jiaodu&&&45)&||&(jiaodu&&&-45&&&&jiaodu&&&0))&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&Debug.Log("右");&&&&&&&&&&&&&&}&&&&&&&&&&}&&&&&&&&&&//按动触发&&&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))&&&&&&&&&&{&&&&&&&&&&&&&&Debug.Log("用press按下了&“Touchpad”&“&”");&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&//&Update&is&called&once&per&frame&&&&&&&&&&void&Update&()&{&&&&&&&&&&&&}&&&&&&//方向圆盘最好配合这个使用&圆盘的.GetAxis()会检测返回一个二位向量,可用角度划分圆盘按键数量&&&&&&//这个函数输入两个二维向量会返回一个夹角&180&到&-180&&&&&&float&VectorAngle(Vector2&from,&Vector2&to)&&&&&&{&&&&&&&&&&float&&&&&&&&&&&Vector3&cross&=&Vector3.Cross(from,&to);&&&&&&&&&&angle&=&Vector2.Angle(from,&to);&&&&&&&&&&return&cross.z&&&0&?&-angle&:&&&&&&&}&&}&&
发表评论:
TA的推荐TA的最新馆藏[转]&unity htc 手柄(2)
using UnityE
using System.C
//检测手柄功能的脚本 这个脚本挂到手柄上(controler(right)和controler(left))上
public class ButtonTouchAction : MonoBehaviour {
SteamVR_TrackedObject trackdeO
void Awake() {
//获取手柄上的这个组件
trackdeObjec = GetComponent&SteamVR_TrackedObject&();
// Use this for initialization
void Start () {
void FixedUpdate()
//获取手柄输入
var device = SteamVR_Controller.Input((int)trackdeObjec.index);
//以下是api中复制出来的按键列表
public class ButtonMask
public const ulong System = (1ul && (int)EVRButtonId.k_EButton_System); // reserved
public const ulong ApplicationMenu = (1ul && (int)EVRButtonId.k_EButton_ApplicationMenu);
public const ulong Grip = (1ul && (int)EVRButtonId.k_EButton_Grip);
public const ulong Axis0 = (1ul && (int)EVRButtonId.k_EButton_Axis0);
public const ulong Axis1 = (1ul && (int)EVRButtonId.k_EButton_Axis1);
public const ulong Axis2 = (1ul && (int)EVRButtonId.k_EButton_Axis2);
public const ulong Axis3 = (1ul && (int)EVRButtonId.k_EButton_Axis3);
public const ulong Axis4 = (1ul && (int)EVRButtonId.k_EButton_Axis4);
public const ulong Touchpad = (1ul && (int)EVRButtonId.k_EButton_SteamVR_Touchpad);
public const ulong Trigger = (1ul && (int)EVRButtonId.k_EButton_SteamVR_Trigger);
//同样是三种按键方式,以后不做赘述
if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) {
Debug.Log(&按了 “trigger” “扳机键”&);
//右手震动
//拉弓类似操作应该就是按住trigger(扳机)gettouch时持续调用震动方法模拟弓弦绷紧的感觉。
var deviceIndex2 = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost);
SteamVR_Controller.Input(deviceIndex2).TriggerHapticPulse(500);
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger))
Debug.Log(&按下了 “trigger” “扳机键”&);
if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) {
Debug.Log(&松开了 “trigger” “扳机键”&);
//左手震动
var deviceIndex = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost);
SteamVR_Controller.Input(deviceIndex).TriggerHapticPulse(3000);
//右手震动
var deviceIndex1 = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost);
SteamVR_Controller.Input(deviceIndex1).TriggerHapticPulse(3000);
//这三种也能检测到 后面不做赘述
if(device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) {
Debug.Log(&用press按下了 “trigger” “扳机键”&);
if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger))
Debug.Log(&用press按了 “trigger” “扳机键”&);
if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
Debug.Log(&用press松开了 “trigger” “扳机键”&);
//system键 圆盘下面那个键
// reserved 为Steam系统保留,用来调出Steam系统菜单 因此貌似自己加的功能没啥用
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.System))
Debug.Log(&按下了 “system” “系统按钮/Steam”&);
if (device.GetPressDown(SteamVR_Controller.ButtonMask.System))
Debug.Log(&用press按下了 “System” “系统按钮/Steam”&);
//ApplicationMenu键 带菜单标志的那个按键(在方向圆盘上面)
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.ApplicationMenu))
Debug.Log(&按下了 “ApplicationMenu” “菜单键”&);
if (device.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu))
Debug.Log(&用press按下了 “ApplicationMenu” “菜单键”&);
//Grip键 两侧的键 (vive雇佣兵游戏中的换弹键),每个手柄左右各一功能相同,同一手柄两个键是一个键。
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Grip))
Debug.Log(&按下了 “Grip” “ ”&);
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip))
Debug.Log(&用press按下了 “Grip” “ ”&);
//Axis0键 与圆盘有交互 与圆盘有关
//触摸触发
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis0))
Debug.Log(&按下了 “Axis0” “方向 ”&);
//按动触发
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Axis0))
Debug.Log(&用press按下了 “Axis0” “方向 ”&);
目前未发现按键位置
//触摸触发
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis1))
Debug.Log(&按下了 “Axis1” “ ”&);
//按动触发
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Axis1))
Debug.Log(&用press按下了 “Axis1” “ ”&);
//Axis2键 目前未发现按键位置
//触摸触发
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis2))
Debug.Log(&按下了 “Axis2” “ ”&);
//按动触发
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Axis2))
Debug.Log(&用press按下了 “Axis2” “ ”&);
未目前未发现按键位置
//触摸触发
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis3))
Debug.Log(&按下了 “Axis3” “ ”&);
//按动触发
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Axis3))
Debug.Log(&用press按下了 “Axis3” “ ”&);
目前未发现按键位置
//触摸触发
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis4))
Debug.Log(&按下了 “Axis4” “ ”&);
//按动触发
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Axis4))
Debug.Log(&用press按下了 “Axis4” “ ”&);
&pre name=&code& class=&csharp&&
//方向圆盘:
//这里开始区分了press检测与touch检测的不同之处,圆盘可以触摸,顾名思义,touch检测的是触摸,press检测的是按动&pre name=&code& class=&csharp&& //Axis0键 与圆盘有交互 与圆盘有关
//触摸触发
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis0))
Debug.Log(&按下了 “Axis0” “方向 ”&);
//按动触发
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Axis0))
Debug.Log(&用press按下了 “Axis0” “方向 ”&);
目前未发现按键位置
//触摸触发
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis1))
Debug.Log(&按下了 “Axis1” “ ”&);
//按动触发
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Axis1))
Debug.Log(&用press按下了 “Axis1” “ ”&);
//Axis2键 目前未发现按键位置
//触摸触发
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis2))
Debug.Log(&按下了 “Axis2” “ ”&);
//按动触发
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Axis2))
Debug.Log(&用press按下了 “Axis2” “ ”&);
未目前未发现按键位置
//触摸触发
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis3))
Debug.Log(&按下了 “Axis3” “ ”&);
//按动触发
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Axis3))
Debug.Log(&用press按下了 “Axis3” “ ”&);
目前未发现按键位置
//触摸触发
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis4))
Debug.Log(&按下了 “Axis4” “ ”&);
//按动触发
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Axis4))
Debug.Log(&用press按下了 “Axis4” “ ”&);
//ATouchpad键 圆盘交互
//触摸触发
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad))
Debug.Log(&按下了 “Touchpad” “ ”&);
//方法返回一个坐标 接触圆盘位置
Vector2 cc = device.GetAxis();
Debug.Log(cc);
// 例子:圆盘分成上下左右
float jiaodu = VectorAngle(new Vector2(1, 0), cc);
Debug.Log(jiaodu);
if (jiaodu & 45 && jiaodu & 135)
Debug.Log(&下&);
if (jiaodu & -45 && jiaodu & -135)
Debug.Log(&上&);
if ((jiaodu & 180 && jiaodu & 135) || (jiaodu & -135 && jiaodu & -180))
Debug.Log(&左&);
if ((jiaodu & 0 && jiaodu & 45) || (jiaodu & -45 && jiaodu & 0))
Debug.Log(&右&);
//按动触发
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
Debug.Log(&用press按下了 “Touchpad” “ ”&);
// Update is called once per frame
void Update () {
//方向圆盘最好配合这个使用 圆盘的.GetAxis()会检测返回一个二位向量,可用角度划分圆盘按键数量
//这个函数输入两个二维向量会返回一个夹角 180 到 -180
float VectorAngle(Vector2 from, Vector2 to)
Vector3 cross = Vector3.Cross(from, to);
angle = Vector2.Angle(from, to);
return cross.z & 0 ? -angle :
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:3850次
排名:千里之外
(2)(4)(2)(4)(2)【用steamVR开发】里面有个蓝色的圈怎么取消掉啊_unity3d吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:54,766贴子:
【用steamVR开发】里面有个蓝色的圈怎么取消掉啊收藏
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或SteamVR_PlayArea 作用|Unity SteamVR插件集成_Unity3D教程_中国AR网
&当前位置: &
重要组件_CameraVR摄像机,主要功能是将Unity摄像机的画面进行变化,形成中的成像画面使用方法:l 在任一个摄像机上增加脚本l 点击Expand按钮完成以上操作后,原本的摄像机会变成如下结构l Origin:位置l Head:头部l Eye:眼睛l Ears:耳朵至此,游戏中Vive中可以看到游戏画面,360度旋转查看游戏世界,在游戏世界中移动等SteamVR_ControllerManager和SteamVR_TrackedObject控制器,主要用于设置和检测Vive控制器。Vive控制器由菜单键(ApplicationMenu),触摸板(Touchpad),系统键/电源键(System),扳机键(Trigger),侧柄键(Grip),组成1 Menu button(菜单键)2 Trackpad(触摸板)3 System button(系统键/电源键)4 Status light5 Micro-USB port6 Tracking sensor7 Trigger(扳机键)8 Grip button(侧柄键)使用方法在Origin物体上添加2个子物体代表Vive的2个手柄,增加SteamVR_TrackedObject,Index设置为None在Origin物体上添加SteamVR_ControllerManager,设置左右手柄至此就完成了手柄的集成。获取手柄状态通过代码var device = SteamVR_Controller.Input(uint);device.GetTouchDown(SteamVR_Controller.ButtonMask)就可以获取到某个按键的状态或者使用var system = OpenVR.Ssystem.GetControllerState(uint, ref VRControllerState_t))获取当前所有的按键状态手柄震动public void TriggerHapticPulse(ushort durationMicroSec = 500, EVRButtonId buttonId = EVRButtonId.k_EButton_SteamVR_Touchpad){var system = OpenVR.Sif (system != null){var axisId = (uint)buttonId - (uint)EVRButtonId.k_EButton_Axis0;system.TriggerHapticPulse(ControllerIndex, axisId, (char)durationMicroSec);}}或者var device = SteamVR_Controller.Input(uint);device. TriggerHapticPulse();SteamVR_RenderModel该组件用于渲染手柄的模型,并且跟踪手柄的位置使用方法在左右手柄的物体下创建一个子物体,子物体上添加SteamVR_RenderModel脚本,Shader可以根据需求设置,比如设置为Standard至此,游戏中可以看到手柄模型和手柄位置同步SteamVR_PlayArea用于显示游玩区域。使用方法,在Origin物体上添加该脚本即可可以看到游戏场景中多了一个显示区域注意事项制作UI的时候需要使用世界坐标,通过不同相机的Depth复合,目前还不支持()注意ControlIndex的值,默认情况下都会自动设置,如果手动设置错误将导致错误的表现。更多就在(/)
中国AR网()为更好的服务国内AR技术爱好者 ,现已推出“AR那些事”官方公众号,请在微信公众账号中搜索「armeiti」或者用手机扫描左方二维码,即可获得每日内容推送和最新的AR开发教程及AR H游戏资源哦!
上一篇: 下一篇:
AR搜索排行榜

我要回帖

更多关于 steamvr unity 的文章

 

随机推荐