vive手柄按键获取

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("你松开了");
	    }
    }
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值