HTC Focus 使用 WaveVR SDk开发----获取手柄按钮事件

场景中拖入Assets\WaveVR\Prefab\WaveVR预制体,删除默认相机就可以在一体机上进行运行。如果需要显示手柄则还需要拖入ControllerLoader预制体,建议放在WaveVR预制体下。

获取手柄按钮事件则需要再拖入一个WaveVRButton预制体到场景中然后使用以下代码进行获取手柄的各个按钮事件

using UnityEngine;
using UnityEngine.VR;
using UnityEngine.XR;

public class InputEventSystem : MonoBehaviour
{
    WaveVR_Controller.Device device;
    // Start is called before the first frame update
    void Start()
    {
        device = WaveVR_Controller.Input(wvr.WVR_DeviceType.WVR_DeviceType_Controller_Right);
        if (WaveVR_ButtonList.Instance != null)
        {
            List<WaveVR_ButtonList.EControllerButtons> _buttons = new List<WaveVR_ButtonList.EControllerButtons>
            {
                WaveVR_ButtonList.EControllerButtons.DPadDown,
                WaveVR_ButtonList.EControllerButtons.DPadLeft,
                WaveVR_ButtonList.EControllerButtons.DPadRight,
                WaveVR_ButtonList.EControllerButtons.DPadUp,
                WaveVR_ButtonList.EControllerButtons.Trigger,
                WaveVR_ButtonList.EControllerButtons.Menu,
                WaveVR_ButtonList.EControllerButtons.VolumeUp
                
            };

            // button list of Dominant hand.
            WaveVR_ButtonList.Instance.SetupControllerButtonList(WaveVR_Controller.EDeviceType.Dominant, _buttons);
        }
    }

    // Update is called once per frame
    void Update()
    {
        if (device.GetPressDown(wvr.WVR_InputId.WVR_InputId_17))
        {
            GameObject.Find("Cube").SetActive(false);
        }
    }
}

下图对应各个按钮的定义

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章