【问题标题】:How can I convert this Unity code to MonoGame code?如何将此 Unity 代码转换为 MonoGame 代码?
【发布时间】:2019-05-30 15:34:47
【问题描述】:

我不知道如何在 MonoGame 项目中使用 PlayFab。我已经阅读了一些 PlayFab 教程,但它们都是针对 Unity 的,我认为无法将 Unity 代码示例与 MonoGame 一起使用,因为我总是收到错误消息。

从这行代码。

PlayFabClientAPI.GetUserInventoryAsync(new GetUserInventoryRequest(), OnGetUserInventoryRequest, OnPlayFabInventoryError);

我在这里收到错误消息:

错误 CS1503:参数 2:无法从“方法组”转换为 '对象'

错误 CS1503:参数 3:无法从“方法组”转换为 '字典'

“OnGetUserInventoryRequest,OnPlayFabInventoryError”有问题,但我不知道我可以改变什么。

我可以进行哪些更改以使此代码与 MonoGame 一起使用?

https://api.playfab.com/documentation/client/method/GetUserInventory

示例代码

public void GetInventoryList()
{
    PlayFabClientAPI.GetUserInventoryAsync(new GetUserInventoryRequest(), OnGetUserInventoryRequest, OnPlayFabInventoryError);
}
public void OnGetUserInventoryRequest(GetUserInventoryResult result)
{
    Console.WriteLine(result.VirtualCurrency);
}

public void OnPlayFabInventoryError(PlayFabError result)
{
    Console.WriteLine("Error");
}

编辑:

如果我想使用 VirtualCurrency 的值,我会收到一条新的错误消息。我不知道如何获取 VirtualCurrency 的值,我做错了什么?

private async Task GetInventoryList()
{
    var result = await PlayFabClientAPI.GetUserInventoryAsync(new GetUserInventoryRequest());

    int CurrentAmount = result.Result.VirtualCurrency;
}

错误 CS0029:无法隐式转换类型 'System.Collections.Generic.Dictionary' 到 'int'

【问题讨论】:

  • GetUserInventoryAsync 的方法签名是什么?
  • 我添加了一张图片。您是指 GetUserInventoryAsync 的方法签名吗?

标签: c# unity3d xamarin monogame


【解决方案1】:

看一下方法签名就很明显了:

GetUserInventoryAsync(GetUserInventoryRequest request, object customData = null, Dictionary<string,string> extraHeaders = null)

最后2个参数是可选的,它们不是回调方法

【讨论】:

  • 谢谢。我对请求的使用还有另一个问题。我需要 VirtualCurrency 的值,但我不知道如何获取该值,因为它不是整数。如何获取 VirtualCurrency 的价值?
  • VirtualCurrency 是一个字典,所以你必须提供一个键来获取一个值 - int CurrentAmount = result.Result.VirtualCurrency["GD"]; 我不知道键(CurrencyCode)的有效值是什么,你需要弄清楚出来了。
  • CurrencyCode 是我在 PlayFab 中的虚拟货币的两个字母代码。谢谢,它现在可以工作了;)
猜你喜欢
  • 2019-11-19
  • 2019-05-26
  • 2018-06-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多