unity htc vive ui的手柄怎么和unity

用户名:速度速度撒
文章数:31
访问量:21680
注册日期:
阅读量:1297
阅读量:3317
阅读量:583377
阅读量:468447
51CTO推荐博文
一、HTC VIVE手柄按键图说明650) this.width=650;" src="/blog/606/94-.png" alt="94-.png" />1 -&菜单键6 -&系统键(按下后手柄断开连接,再次按下手柄再次连接上)7 -&扳机键8 -&握持键9 -&触摸板键二、按键的监听方式& &1、按键监听方式一:(SteamVR的方式,封装了OpenVR)& (1)点击触发:通过Device.GetPressDown / GetPressUp / GetPress获取按键事件& (2)触摸触发:通过device .GetTouchDown / GetTouchUp / GetTouch获取按键事件& &2、按键监听方式二:(OpenVR的方式,偏底层)& 通过controllerState.ulButtonPressed & (SteamVR_Controller.ButtonMask.Trigger)获取按键的按下、松开两种状态650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url(&/e/u261/lang/zh-cn/images/localimage.png&) no-border:1px solid #" alt="spacer.gif" />&650) this.width=650;" src="/blog/606/09-.png" alt="" style="border:0margin:0padding:0" />或者:650) this.width=650;" src="/blog/606/97-.png" alt="" style="border:0margin:0padding:0" />注:m_State、m_PrevState分别表示:当前帧状态、前一帧状态获取按下时,触摸板的值&650) this.width=650;" src="/blog/606/90-.png" alt="" style="border:0margin:0padding:0" />获取松开时,触摸板的值(这里必须使用前一帧的状态,因为松开时,当前帧的触摸的值为0)650) this.width=650;" src="/blog/606/15-.png" alt="" style="border:0margin:0padding:0" />问题:按下时,没有获取到当前帧触摸板的值!猜测原因:获取值的Update方法在更新状态Update的方法之前执行了,更新状态的Update方法执行后,才能获取触摸板的值解决方法:如果不想修改脚本执行顺序的话,可以使用LateUpdate触摸适用于触摸板键适用于扳机键(和点按类似,只是键程更短)方式一:650) this.width=650;" src="/blog/606/09-.png" alt="" style="border:0margin:0padding:0" />方式二:650) this.width=650;" src="/blog/606/69-.png" alt="" style="border:0margin:0padding:0" />问题:触摸按下时,没有获取到当前帧触摸板的值!原因:不明,内部机制需要搞清楚解决办法:在触摸按下后的第二帧才获取到触摸板的值。&650) this.width=650;" src="/blog/606/31-.png" alt="" style="border:0margin:0padding:0" />(3)触摸板轴的获取通过以上两种方式获取的VRControllerState_t,获取触摸板的轴x = state.rAxis0.xy = state.rAxis0.y三、代码使用总结如下//检测手柄功能的脚本&这个脚本挂到手柄上(controller(right)和controller(left))上&&&&&&public&class&HTCStick&:&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);&&&&&&&&&&&&&&}&&&&&&&&&&&&&&*/&&&&&&&&&&&&//每种按键都有GetTouch、GetTouchDown、GetTouchUp、GetPressDown、GetPress、GetPressUp&&&&&&&&&&//这里只有Trigger扳机键写了6种,其他的不再重复。&&&&&&&&&&//Trigger的Touch触发条件是扳机键没有按到底,此时不会触发press。触发press时必定触发touch。&&&&&&&&&&&&&&if&(device.GetTouch&(SteamVR_Controller.ButtonMask.Trigger))&{&&&&&&&&&&&&&&Debug.Log&("轻按了扳机键");&&&&&&&&&&&&&&//右手震动&&&&&&&&&&&&&&&&&&//拉弓类似操作应该就是按住trigger(扳机)gettouch时持续调用震动方法模拟弓弦绷紧的感觉。&&&&&&&&&&&&&&&&&&var&deviceIndex2&=&SteamVR_Controller.GetDeviceIndex&(SteamVR_Controller.DeviceRelation.Rightmost);&&&&&&&&&&&&&&device.TriggerHapticPulse&(1200);&&&&&&&&&&}&&&&&&&&&&&&if&(device.GetTouchDown&(SteamVR_Controller.ButtonMask.Trigger))&{&&&&&&&&&&&&&&Debug.Log&("轻按了扳机键");&&&&&&&&&&}&&&&&&&&&&&&if&(device.GetTouchUp&(SteamVR_Controller.ButtonMask.Trigger))&{&&&&&&&&&&&&&&Debug.Log&("松开了扳机键");&&&&&&&&&&&&&&&&//左手震动&&&&&&&&&&&&&&&&&&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系统按钮");&&&&&&&&&&}&&&&&&&&&&if&(device.GetPressDown&(SteamVR_Controller.ButtonMask.System))&{&&&&&&&&&&&&&&Debug.Log&("用press按下了系统按钮");&&&&&&&&&&}&&&&&&&&&&&&//ApplicationMenu键&带菜单标志的那个按键(在方向圆盘上面)&&&&&&&&&&&&&&//ApplicationMenu键&的Touch和Press没有区别,触发都要按下去&&&&&&&&&&if&(device.GetTouchDown&(SteamVR_Controller.ButtonMask.ApplicationMenu))&{&&&&&&&&&&&&&&Debug.Log&("按下了&ApplicationMenu菜单键");&&&&&&&&&&}&&&&&&&&&&if&(device.GetPressDown&(SteamVR_Controller.ButtonMask.ApplicationMenu))&{&&&&&&&&&&&&&&Debug.Log&("用press按下了ApplicationMenu菜单键");&&&&&&&&&&}&&&&&&&&&&&&//Grip键&手柄两侧的按键&每个手柄左右各一且功能相同,同一手柄两个键是一个键。&&&&&&&&&&&&&//Grip键&的Touch和Press没有区别,触发都要按下去&&&&&&&&&&if&(device.GetTouchDown&(SteamVR_Controller.ButtonMask.Grip))&{&&&&&&&&&&&&&&Debug.Log&("按下了&Grip");&&&&&&&&&&}&&&&&&&&&&if&(device.GetPressDown&(SteamVR_Controller.ButtonMask.Grip))&{&&&&&&&&&&&&&&Debug.Log&("用press按下了&Grip");&&&&&&&&&&}&&&&&&&&&&&&//Axis0键和Touchpad是等价的&与圆盘有关&详情看下面的TouchPad这里不再赘述&&&&&&&&&&//触摸触发&&&&&&&&&&&&&&if&(device.GetTouchDown&(SteamVR_Controller.ButtonMask.Axis0))&{&&&&&&&&&&&&&&Debug.Log&("按下了&Axis0");&&&&&&&&&&}&&&&&&&&&&//按动触发&&&&&&&&&&&&&&if&(device.GetPressDown&(SteamVR_Controller.ButtonMask.Axis0))&{&&&&&&&&&&&&&&Debug.Log&("用press按下了Axis0");&&&&&&&&&&}&&&&&&&&&&&&//Axis1键&&等价于Trigger键详情看上面的Trigger按钮&这里不再赘述&&&&&&&&&&//触摸触发&&&&&&&&&&&&&&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");&&&&&&&&&&}&&&&&&&&&&&&//Touchpad键&圆盘交互&&&&&&&&&&&&&&//触摸触发&&&&&&&&&&&&&&if&(device.GetTouchDown&(SteamVR_Controller.ButtonMask.Touchpad))&{&&&&&&&&&&&&&&Debug.Log&("按下了&Touchpad");&&&&&&&&&&&&&&&&//方法返回一个坐标&接触圆盘位置&&&&&&&&&&&&&&&&&&Vector2&cc&=&device.GetAxis&();&&&&&&&&&&&&&&Debug.Log&(cc);&&&&&&&&&&&&&&//&例子:圆盘分成上下左右&&&&&&&&&&&&&&&&&&float&angle&=&VectorAngle&(new&Vector2&(1,&0),&cc);&&&&&&&&&&&&&&Debug.Log&(angle);&&&&&&&&&&&&&&//下&&&&&&&&&&&&&&&&&&if&(angle&&&45&&&&angle&&&135)&{&&&&&&&&&&&&&&&&&&Debug.Log&("下");&&&&&&&&&&&&&&}&&&&&&&&&&&&&&//上&&&&&&&&&&&&&&&&&&if&(angle&&&-45&&&&angle&&&-135)&{&&&&&&&&&&&&&&&&&&Debug.Log&("上");&&&&&&&&&&&&&&}&&&&&&&&&&&&&&//左&&&&&&&&&&&&&&&&&&if&((angle&&&180&&&&angle&&&135)&||&(angle&&&-135&&&&angle&&&-180))&{&&&&&&&&&&&&&&&&&&Debug.Log&("左");&&&&&&&&&&&&&&}&&&&&&&&&&&&&&//右&&&&&&&&&&&&&&&&&&if&((angle&&&0&&&&angle&&&45)&||&(angle&&&-45&&&&angle&&&0))&{&&&&&&&&&&&&&&&&&&Debug.Log&("右");&&&&&&&&&&&&&&}&&&&&&&&&&}&&&&&&&&&&//按动触发&&&&&&&&&&&&&&if&(device.GetPressDown&(SteamVR_Controller.ButtonMask.Touchpad))&{&&&&&&&&&&&&&&Debug.Log&("用press按下了Touchpad");&&&&&&&&&&&&&&Vector2&cc&=&device.GetAxis&();&&&&&&&&&&&&&&Debug.Log&(cc);&&&&&&&&&&}&&&&&&}&&&&&&//&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&:&&&&&&&}&&} &本文出自 “” 博客,请务必保留此出处
了这篇文章
类别:┆阅读(0)┆评论(0)您的位置:
→ Htc Vive虚拟手柄使用技巧汇总
Htc Vive虚拟手柄使用技巧汇总
Htc Vive用虚拟手柄的玩家会遇到各式各样的问题,下面跟大家整理一下虚拟手柄的使用技巧汇总给各位分享。小贴士:1.用虚拟手柄驱动,一定要注意启动顺序,先启动两个手柄,并放在基站可以定位的地方,然后再启动steamvr,最后启动游戏。2.使用阅读原文中的校准工具时,关掉第三手柄模式,才能看到实时预览。3.用虚拟手柄驱动的朋友,不用虚拟手柄的时候可以把steamvrsettings里面的允许多驱动给改成false,要用的时候再换成true。4.使用阅读原文中的校准工具,可以直接在左下角看到预览,打开obs和相机,在这里面调整至完全重叠,可以提高效率。5.用绿幕的时候注意人不要离绿幕太近,光线一定要充足,不然人会范绿,抠图的时候会很难看。特别是用大面积绿幕的朋友,一定要让光源直接打在人身上,而不是先打在绿幕上在反射。所以我一般除了上面打光以外,还会做一些摄像机灯光。6.如果觉得obs截取的画质差,可能是因为窗口太小。如果把窗口直接拉大unity会重新适配分辨率的,也就是说假设你是4k的屏幕,4分屏调到全屏,每个分屏才有1080p。如果没有4k屏幕可以直接把屏幕脱出显示范围,像素一样会渲染的,obs也可以捕捉到。这个方面我确实不知道更好的方法,我人也比较懒,如果有更好的方法请分享给我。7.如果你发现你的画面有延迟,往往是硬件缺陷,但也可以通过降低分辨率和比特率来降低延迟,但效果不明显。8.其实如果你不打算拍影视级别大作,那么480p就够了。而且用告诉摄像头,往往比用摄像机加采集卡容易,问题也比较少。然后你把mr视频放一半第视角放一半,最后还是有一个高清视频。这样你拍mr视频的成本只要几百块钱,而其他可行方法动辄上万。9。用广角镜头对准场景会更简单,道理我不用多解释吧。但是画面可素性比较底,换句话就是不适合拍mr电影。
阅读此文的人还阅读了...
美国美国 跑跑车网友 发表于:
是这个吗 cameraAlign
美国美国 跑跑车网友 发表于:
&#26657;&#20934;&#24037;&#20855; &#22312;&#21738;&#37324;分享给朋友:通用代码: <input id="link4" type="text" class="form_input form_input_s" value="" />复 制Unity3D维度空间实验室HtcVive第6次实验:手柄功能开发测试下载至电脑扫码用手机看用或微信扫码在手机上继续观看二维码2小时内有效Unity3D维度空间实验室HtcVive第6次实验:手柄功能开发测试扫码用手机继续看用或微信扫码在手机上继续观看二维码2小时内有效,扫码后可分享给好友没有优酷APP?立即下载请根据您的设备选择下载版本
药品服务许可证(京)-经营- 请使用者仔细阅读优酷、、、Copyright(C)2017 优酷
版权所有不良信息举报电话:

我要回帖

更多关于 unity vive 手柄射线 的文章

 

随机推荐