基本的Oculus Leaderboards.GetEntries API使用会引发错误

时间:2018-04-10 03:57:51

标签: c# unity3d oculus

尝试对排行榜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 leaderBoard.Start()(在Assets / leaderBoard.cs:10)

1 个答案:

答案 0 :(得分:1)

在致电Leaderboards.GetEntries之前,您必须使用App ID初始化SDK,然后进行权利检查。如果通过,则可以调用Leaderboards.GetEntries函数。假设您的应用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();
}