【问题标题】:How to get data from joystick controller generator in Unity C#如何从 Unity C# 中的操纵杆控制器生成器获取数据
【发布时间】:2016-05-03 00:34:16
【问题描述】:

我使用 AirConsole 控制器生成器创建了一个操纵杆,它说它将把它发送到屏幕:

{
    joystick-left: {
        pressed: true|false,
        message: { x: Number, y: Number }
    }
}

现在我不知道如何在 Unity 中解析它。这是我尝试过的:

void OnMessage(int receivedID, JToken receivedData)
{
    bool pressed = (bool)receivedData["pressed"];
    float directionX = (float)receivedData["message"]["x"];
    float directionY = (float)receivedData["message"]["y"];
}

当我尝试将 press 转换为 bool 时,它给了我 ArgumentNullException: Argument cannot be null。我也不知道应该使用什么语法来获取操纵杆方向。

如何将信息解析为 C# Unity?

【问题讨论】:

    标签: airconsole


    【解决方案1】:

    我完全不熟悉 C# 或 Unity,但你必须做 s.t.喜欢:

    // Sorry, I don't know the type, but assume its 'JToken'
    JToken joystick_data = (JToken)receivedData["joystick-left"];
    
    // And then to get the other params:
    bool pressed = (bool)joystick_data["pressed"];
    float directionX = (float)joystick_data["message"]["x"];
    // ...
    

    【讨论】:

      猜你喜欢
      • 2018-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多