HTC Vive开发笔记1

来源:互联网 发布:晓风软件 编辑:程序博客网 时间:2024/05/16 17:51

HTC Vive开发笔记1

原生SteamVR插件

  • 引用命名空间:using Valve.VR;
  • 获取手柄对象: trackedObj = GetComponent<SteamVR_TrackedObject>();
  • 判断手柄状态:
int index = (int)trackedObject.index;if(index == -1) return;  //当index为-1时,表示手柄没有开启
  • 获取手柄转换: Transform handCtrlObj = trackedObj.transform;
  • 获取手柄输入: var device = SteamVR_Controller.Input((int)trackedObj.index));
  • 监听手柄按键: (下面以按键Trigger为例)
//按下按键(扣下扳机)bool isDown = device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger);//松开按键(松开扳机)bool isUp = device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger);//长按按键(长扣扳机)bool isPress = device.GetPress(SteamVR_Controller.ButtonMask.Trigger);
  • 获取按键Pad的触摸坐标:Vector2 vector = device.GetAxis();
  • 手柄震动:device.TriggerHapticPulse();

Vive Input Utility插件

该插件左右手柄是区分开的,下面以右手柄HandRole.RightHand为例

  • 引用命名空间:using HTC.UnityPlugin.Vive;
  • 判断手柄状态:if(!ViveRole.IsValidIndex(0)) return;
  • 监听手柄按键:
bool isDown = ViveInput.GetPressDown(HandRole.RightHand, ControllerButton.Trigger);bool isUp = ViveInput.GetPressUp(HandRole.RightHand, ControllerButton.Trigger);bool isPress = ViveInput.GetPress(HandRole.RightHand, ControllerButton.Trigger);
  • 获取按键Pad的触摸坐标:Vector2 vector = ViveInput.GetPadTouchAxis(HandRole.RightHand);
  • 获取扳机Trigger的按下程度:float value = ViveInput.GetTriggerValue(HandRole.RightHand);
  • 手柄震动:ViveInput.TriggerHapticPulse(HandRole.RightHand);
0 0
原创粉丝点击