【问题标题】:How do I get input from the Oculus remote?如何从 Oculus 遥控器获取输入?
【发布时间】:2017-09-26 12:03:52
【问题描述】:

我正在尝试弄清楚如何在 Unity3D 5.3.4f 中使用 oculus 遥控器。我找到了一些关于 OVR 映射的 documentation,但我似乎无法弄清楚。

我想要实现的是单击中间按钮(Button.One)时。

我现在用的是这行代码

if (OVRInput.GetUp(OVRInput.Button.One))
    {
        Debug.Log("remote click");
    }

但是当我运行应用程序时,我得到了这个错误。

NullReferenceException:对象引用未设置为对象的实例 OVRInput.GetUp(按钮 virtualMask,控制器 controllerMask)(在 Assets/OVR/Scripts/OVRInput.cs:600) menuButtonHandler.Update() (在 Assets/menuButtonHandler.cs:136)

可以在这个脚本中找到

/// <summary>
/// Gets the current up state of the given virtual button mask with the given controller mask.
/// Returns true if any masked button was released this frame on any masked controller and no other masked button is still down this frame.
/// </summary>
public static bool GetUp(Button virtualMask, Controller controllerMask = Controller.Active)
{
    return OVRManager.input.GetResolvedButtonUp(virtualMask, RawButton.None, controllerMask);
}

有没有人在unity之前使用过Oculus遥控器并且可以帮助我?

谢谢,

约翰

【问题讨论】:

    标签: c# unity3d oculus


    【解决方案1】:

    在调用 GetUp() 之前,可能需要初始化该方法中的一个对象。

    仔细查看您的初始化代码,以及您可能拥有的任何示例——我敢打赌,您会在不看太多之后发现缺少的东西。我对 Unity API 不熟悉,但如果它们是 PC 或移动 C++ API 之类的东西,你很可能错过了一步,或者忘记了启动 VR 服务。

    【讨论】:

    • 谢谢你的回答。我已经将我的代码一直放在脚本文件的末尾。但它似乎仍然不起作用。真是奇怪的东西
    • 没关系,找到了解决方案。我正在使用错误的相机预制件。您必须使用包中的 OVRcameracontroller。
    【解决方案2】:

    要在 Unity 版本 2017.1.1 中使用输入,您必须首先下载“Oculus Utilities for Unity”

    Oculus Utilities asset package for Unity

    然后你必须在 Unity 中导入包, 去: -- "资产" --> "导入包" --> "自定义包"

    浏览您的“Oculus 实用程序下载”

    点击导入

    在调用输入检查函数之前调用函数“OVRInput.update()”。

    void Update ()
        {
            OVRInput.Update(); // Call before checking the input
    
            if (OVRInput.Get(OVRInput.Button.DpadLeft)) {
                print("left button pressed");
            }
            if (OVRInput.Get(OVRInput.Button.DpadRight)) {
                print("right button pressed");
            }
            if (OVRInput.Get(OVRInput.Button.One)) {
                print("round button pressed");
            }
        }
    

    有关 OVRInput 的更多信息,请查看此链接

    OVRInput

    【讨论】:

      猜你喜欢
      • 2019-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多