using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UserViveHand : MonoBehaviour
{
public SteamVR_TrackedObject Hand;
private SteamVR_Controller.Device device;
void Start ()
{
Hand = GetComponent<SteamVR_TrackedObject>();
}
// Update is called once per frame
void Update () {
device = SteamVR_Controller.Input((int)Hand.index);
// 按下了扳机按钮调用
if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
{
Debug.Log("trigger");
}
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
{
Debug.Log("PressDown");
}
if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
{
Debug.Log("PressUp");
}
// 当手放置在触摸圆盘上的时候调用
if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
{
Debug.Log("touchpad");
// 获取触摸板上的坐标
Vector2 pad = device.GetAxis();
Debug.Log("按下了" + pad);
// 转换角度
Vector3 cross = Vector3.Cross(new Vector2(1, 0), pad);
float angle = Vector2.Angle(new Vector2(1, 0), pad);
float ang = cross.z > 0 ? -angle : angle;
Debug.Log(ang);
}
// 按下面板的时候打印
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis0))
{
Debug.Log("Axis0");
}
// 按下扳机键的时候打印
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis1))
{
Debug.Log("Axis1");
}
//左手震动
var device1 = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost);
SteamVR_Controller.Input(device1).TriggerHapticPulse(2000);
// 获取左右手柄的标志
var device2 = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost);
// 设置获取手柄的震动值
SteamVR_Controller.Input(device2).TriggerHapticPulse(100);
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.ApplicationMenu))
{
Debug.Log("你按下了菜单键");
}
//抓握按键手柄左右两侧的抓握按键为一个按键
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Grip))
{
Debug.Log("你正紧握");
}
if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Grip))
{
Debug.Log("你松开了");
}
}
}
vive手柄按键获取
最新推荐文章于 2022-12-19 15:03:29 发布