您当前的位置: 首页 >  vr

每日出拳老爷子

暂无认证

  • 4浏览

    0关注

    135博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Unity VR:定位VR输入设备的两种思路

每日出拳老爷子 发布时间:2022-03-13 02:47:32 ,浏览量:4

背景

定位VR输入设备是开发游戏所必需的,具体实现上总结出两条道路。

具体方法
  1. 第一条路,就是传统的从物理Device探知入手,这部分已经写过帖子,主要就是从Inputdevice类下手,获得所有Inputdevice后找具备相应characteristic的device。这条路的优点在于单刀直入,容易理解,捕获也比较准确,毕竟是直接先定位物理设备,然后再捕获设备输入。但是,缺点在于写起来比较繁琐,因为物理Device是无法直接作为Public映射到实际对象上的。
  2. 第二条路,就是活动新版InputSystem,通过Action反推到DeviceName,然后判断倒地触法了哪个Device的动作。这条路的优点是写法比较简便,并且不需要在Update中另写方法,和actionRef一气呵成。
  3. 例子:public List grip_ref = null; public List trigger_ref = null; 界面上加所有相关的actionRef放到希望触发一类动作的actionList里面。
    private void Awake()
    {
        foreach(var ele in grip_ref)
        {
            ele.action.performed += set_grab;
        }
        foreach (var ele in trigger_ref)
        {
            ele.action.performed += set_trigger;
        }
    }

这一步在Awake函数中配置好每一类action希望做的事。

    private void set_grab(InputAction.CallbackContext context)
    {
        float cur_grab_value = context.action.ReadValue();
        if (context.control.device.name == "Keyboard")
        {
            Debug.Log("key");
        }
        else
        {
            Debug.Log(context.control.device.name);
        }
    }

    private void set_trigger(InputAction.CallbackContext context)
    {
        Debug.Log("Trigger");
        if (context.control.device.name == "Keyboard")
        {
            Debug.Log("key");
        }
        else
        {
            Debug.Log(context.control.device.name);
        }
    }

写具体的处理函数。

关注
打赏
1657016083
查看更多评论
立即登录/注册

微信扫码登录

0.0364s