基本 Oculus Leaderboards.GetEntries API 用法抛出错误

Basic Oculus Leaderboards.GetEntries API usage throws errors

尝试对排行榜进行简单调用 API 失败。我什至尝试复制并粘贴文档的一些示例代码,但它们也都因相同的错误而失败。下面是我能想出的最简单的版本,但它也失败了。我的Oculus开发者设置是统一设置的。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Oculus.Platform;
using Oculus.Platform.Models;

public class leaderBoard : MonoBehaviour {

    void Start () {
        Leaderboards.GetEntries("POC-Score", 10, LeaderboardFilterType.None, LeaderboardStartAt.Top).OnComplete(GetEntriesCallback);
    }

    void GetEntriesCallback(Message<LeaderboardEntryList> msg)
    {
        Debug.Log("-----");
        Debug.Log(msg.Data);
        Debug.Log("-----");
    }
}

我收到以下错误

NullReferenceException: Object reference not set to an instance of an object leaderBoard.Start () (at Assets/leaderBoard.cs:10)

调用Leaderboards.GetEntries之前,您必须使用App ID初始化SDK,然后进行权限检查。如果通过,您可以调用 Leaderboards.GetEntries 函数。假设你的App ID是857362746724,初始化为:

Core.Initialize("857362746724");

现在,进行权利检查。如果成功,调用Leaderboards.GetEntries函数:

void checkEntitlement()
{
    Entitlements.IsUserEntitledToApplication().OnComplete(
    (Message msg) =>
    {
        if (msg.IsError)
        {
            // User is NOT entitled.
            Debug.Log("Error: User not entitled");
        } else 
        {
            // User IS entitled
            Debug.Log("Success: User entitled");
            checkEntry();
        }
    }
);
}

void checkEntry()
{
    Leaderboards.GetEntries("POC-Score", 10, LeaderboardFilterType.None, LeaderboardStartAt.Top).OnComplete(GetEntriesCallback);
}

void GetEntriesCallback(Message<LeaderboardEntryList> msg)
{
    Debug.Log("-----");
    Debug.Log(msg.Data);
    Debug.Log("-----");
}

有了 Start 函数,它应该如下所示:

void Start()
{
    Core.Initialize("857362746724");
    checkEntitlement();
}