1、手柄的详细介绍。

手柄对象一栏: http://www.jianshu.com/p/c28fbf480cff

2、获取手柄上按键的对应信息

2-1 :获取手柄编号
        // 手柄组件
        Left = GetComponent<SteamVR_TrackedObject>();
        // 获取手柄编号(左手柄  == 2)
        Debug.Log((int)Left.index);

在手柄上挂载此脚本

打印结果
2-2 : 获取扳机按键
       // 按下了扳机按钮调用
        if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
        {
            Debug.Log("trigger");
        }

第二种方式也是Ok的
if (device.GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger))
        {
            print("123");
        }

Paste_Image.png
        // 按下手柄左右的对称按钮调用,而且调用频率跟刷新频率一致
        if (device.GetTouch(SteamVR_Controller.ButtonMask.Grip))
        {
            Debug.Log("Grip");
        }

Paste_Image.png
2-3:获取grid
       // 按下手柄左右的对称按钮调用,而且调用频率跟刷新频率一致
        if (device.GetTouch(SteamVR_Controller.ButtonMask.Grip))
        {
            Debug.Log("Grip");
        }
2-4:获取圆盘

Paste_Image.png
 // 当手放置在触摸圆盘上的时候调用
        if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
        {
            Debug.Log("touchpad");
        }

       // 当手放置在触摸圆盘上的时候调用
        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);  
            //根据角度来判断上下左右四个范围

        }
2-5:关于Axis
        // 按下面板的时候打印
        if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis0))
        {
            Debug.Log("Axis0");
        }
        // 按下扳机键的时候打印
        if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis1))
        {
            Debug.Log("Axis1");
        }
    其他的Axis2,3,4暂时还没有什么能够触发

3、手柄的震动

             //左手震动  
            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);
posted on 2017-06-07 10:09  觅Joanna  阅读(1952)  评论(0编辑  收藏  举报