HandRole包括
public enum HandRole
{
Invalid = -1,
RightHand,
LeftHand,
ExternalCamera,
Controller3 = ExternalCamera,
Controller4,
Controller5,
Controller6,
Controller7,
Controller8,
Controller9,
Controller10,
Controller11,
Controller12,
Controller13,
Controller14,
Controller15,
}
按钮包括
- 开关、系统菜单按钮:只有这个按钮不可以编程(默认),用来打开手柄,其实没用关的功能。在游戏中按下该按钮是调出系统默认的菜单,用来关闭,切换游戏用的。
- menu按钮:默认用来打开游戏菜单。
- grip按钮:用的最少的按钮,每个手柄上虽然有两个,但是是相同的。
- trigger按钮:扳机按钮,用的最多,可以有力度。
- pad:触摸屏+鼠标的功能,可触摸,可点击。
public enum ControllerButton
{
[InvalidEnumArrayIndex]
None = -1,
// classic buttons
System = 14,
Menu = 4, // Cosmos(RightHandB, LeftHandY), Index(B)
MenuTouch = 7, // Cosmos(RightHandB, LeftHandY), Index(B)
Trigger = 0, // on:0.55 off:0.45
TriggerTouch = 8, // on:0.25 off:0.20
Pad = 1,
PadTouch = 3,
Joystick = 47,
JoystickTouch = 48,
Grip = 2,
GripTouch = 9,
CapSenseGrip = 10, // on:1.00 off:0.90 // Knuckles, Oculus Touch only
CapSenseGripTouch = 11, // on:0.25 off:0.20 // Knuckles, Oculus Touch only
ProximitySensor = 15,
Bumper = 16,
BumperTouch = 17,
AKey = 12, // Knuckles(InnerFaceButton), Oculus Touch(RightHandA or LeftHandX pressed), Cosmos(RightHandA, LeftHandX), Index(A)
AKeyTouch = 13, // Knuckles(InnerFaceButton), Oculus Touch(RightHandA or LeftHandX touched), Cosmos(RightHandA, LeftHandX), Index(A)
// button alias
BKey = Menu,
BkeyTouch = MenuTouch,
OuterFaceButton = Menu, // 7
OuterFaceButtonTouch = MenuTouch, // 9
InnerFaceButton = AKey, // 12
InnerFaceButtonTouch = AKeyTouch, // 13
[HideInInspector]
Axis0 = Pad,
[HideInInspector]
Axis1 = Trigger,
[HideInInspector]
Axis2 = CapSenseGrip,
[HideInInspector]
Axis3 = Bumper,
[HideInInspector]
Axis4 = 18,
[HideInInspector]
Axis0Touch = PadTouch,
[HideInInspector]
Axis1Touch = TriggerTouch,
[HideInInspector]
Axis2Touch = CapSenseGripTouch,
[HideInInspector]
Axis3Touch = BumperTouch,
[HideInInspector]
Axis4Touch = 19,
// virtual buttons
HairTrigger = 5, // Pressed if trigger button is pressing, unpressed if trigger button is releasing
FullTrigger = 6, // on:1.00 off:1.00
DPadLeft = 20,
DPadUp = 21,
DPadRight = 22,
DPadDown = 23,
DPadLeftTouch = 24,
DPadUpTouch = 25,
DPadRightTouch = 26,
DPadDownTouch = 27,
DPadUpperLeft = 28,
DPadUpperRight = 29,
DPadLowerRight = 30,
DPadLowerLeft = 31,
DPadUpperLeftTouch = 32,
DPadUpperRightTouch = 33,
DPadLowerRightTouch = 34,
DPadLowerLeftTouch = 35,
DPadCenter = 36,
DPadCenterTouch = 37,
// Gestures
IndexPinch = 38,
MiddlePinch = 39,
RingPinch = 40,
PinkyPinch = 41,
Fist = 42,
Five = 43,
Ok = 44,
ThumbUp = 45,
IndexUp = 46,
[Obsolete]
[HideInInspector]
JoystickToucn = 48,
}
1、静态类Vive Input
public class GetPressDown_ViveInput : MonoBehaviour
{
private void Update()
{
if (ViveInput.GetPressDown(HandRole.RightHand,ControllerButton.Trigger))
{
//TODO
}
}
}
2、?监听按钮事件:? ?
public class GetPressDown_ViveInputHandler : MonoBehaviour
{
private void Awake()
{
ViveInput.AddPressDown(HandRole.LeftHand, ControllerButton.Trigger, Ontrigger);
}
private void OnDestroy()
{
ViveInput.RemovePressDown(HandRole.LeftHand,ControllerButton.Trigger, Ontrigger);
}
private void Ontrigger()
{
throw new NotImplementedException();
}
}
3、获得追踪pose:? ? ? ? ?? ?? ?? ?静态类VivePose提供了获得设备pose的API;? ?
public class GetPoseExample : MonoBehaviour
{
//使go跟随右手
public GameObject deviceOrigin;
public Transform goTrans;
private void Start()
{
deviceOrigin = GameObject.Find("VROrigin");
}
private void Update()
{
VivePose.SetPose(goTrans, HandRole.RightHand, deviceOrigin.transform);
}
}
事件响应
vive支持以下事件?
- IColliderEventHoverEnterHandler
- IColliderEventHoverExitHandler
- IColliderEventPressDownHandler
- IColliderEventPressUpHandler
- IColliderEventPressEnterHandler
- IColliderEventPressExitHandler
- IColliderEventClickHandler
- IColliderEventDragStartHandler
- IColliderEventDragUpdateHandler
- IColliderEventDragEndHandler
- IColliderEventDropHandler
- IColliderEventAxisChangedHandler
使用方法,新建脚本如下,并把脚本添加到游戏对象,即可。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HTC.UnityPlugin.ColliderEvent;
public class viveLearn : MonoBehaviour,IColliderEventHoverEnterHandler
{
public void OnColliderEventHoverEnter(ColliderHoverEventData eventData){
Debug.Log ("hover");
}
}
引用链接:ViveInputUtility开发HTC VIVE 手柄控制按键_yuanpan的专栏-CSDN博客
【Unity+Vive】第一篇:Vive Input Utility的使用指南_罗锦荣的专栏-CSDN博客_viveinpututility使用指南
|