如何在v7.2.2中获得玩家的分数

时间:2015-11-08 18:38:59

标签: facebook-unity-sdk

在v6.x中得到我正在使用的分数

FB.API("/me/scores", HttpMethod.GET, LoadScoreCallback)

其中LoadScoreCallback使用FBResult。由于FBResult已被7.x中的IGraphResult取代,因此我无法通过它获得分数。有谁知道怎么做?

1 个答案:

答案 0 :(得分:4)

IGraphResult从FB.API回复" / me / scores"具有您在v7.x +

中所期望的分数数据

以下是解析结果的示例代码(注意:您应该添加错误处理):

void handleScoresResponse (IGraphResult result)
{
    UnityEngine.Debug.Log(result.RawResult);

    var dataList = result.ResultDictionary["data"] as List<object>;
    var dataDict = dataList[0] as Dictionary<string, object>;

    long score = (long)dataDict["score"];
    var user = dataDict["user"] as Dictionary<string, object>;

    string userName = user["name"] as string;
    string userID = user["id"] as string;

    UnityEngine.Debug.Log(userName + ": " + score);
}

请参阅: Facebook Unity SDK Sample usage of me/scores