获取按钮
方法一:
先定义
public SteamVR_Action_Boolean disk;
使用
disk.GetLastStateDown(SteamVR_Input_Sources.Any);
方法二:
SteamVR_Actions.default_GrabGrip.GetStateDown(SteamVR_Input_Sources.LeftHand)
可以获取按键功能
方法三:
public SteamVR_Action_Boolean steamVR_Action_Boolean= SteamVR_Input.GetBooleanAction("Teleport");
public SteamVR_Action_Boolean teleportAction = SteamVR_Input.GetAction("Teleport");
判断手柄按键的状态
private void Start()
{
SteamVR_Actions.default_GrabGrip.onStateDown += Default_GrabGrip_onStateDown;
}
private void Default_GrabGrip_onStateDown(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
{
Debug.Log(":不分左右手:" + fromSource);
throw new System.NotImplementedException();
}
private void Update()
{
if (SteamVR_Actions.default_GrabGrip.GetStateDown(SteamVR_Input_Sources.LeftHand))
{
Debug.Log("左手按下");
}
if (SteamVR_Actions.default_GrabGrip.stateDown)
{
if (SteamVR_Actions.default_GrabGrip.activeDevice == SteamVR_Input_Sources.LeftHand)
{
Debug.Log("左手");
}
Debug.Log("不分左右手");
}
}
事件的注册
public SteamVR_Action_Boolean touch;
public SteamVR_Action_Boolean press;
public SteamVR_Action_Vector2 touchPos;
private void Awake()
{
touch.onChange += Touch;
press.onStateDown += Press;
press.onStateUp += PressRelease;
touchPos.onAxis += TouchPostion;
}
private void OnDestroy()
{
touch.onChange -= Touch;
press.onStateDown -= Press;
press.onStateUp -= PressRelease;
touchPos.onAxis -= TouchPostion;
}
private void Touch(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource, bool newState)
{
Debug.Log("触摸");
}
private void Press(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
{
Debug.Log("手指点击圆盘");
}
private void PressRelease(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
{
Debug.Log("圆盘点击键返回");
}
private void TouchPostion(SteamVR_Action_Vector2 fromAction, SteamVR_Input_Sources fromSource, Vector2 axis, Vector2 delta)
{
Debug.Log("位置:" + axis);
}
还可以直接绑定
public SteamVR_Action_Boolean steamVR_Action_Boolean;
private void Start()
{
SteamVR_Actions.default_GrabGrip.onStateDown += Default_GrabGrip_onStateDown;
}
private void Default_GrabGrip_onStateDown(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
{
Debug.Log(":不分左右手:" + fromSource);
throw new System.NotImplementedException();
}
如果觉得《steamvr unity 连接眼镜_unity Steam VR 手柄按键基本操作》对你有帮助,请点赞、收藏,并留下你的观点哦!