mac os x 设备上的 Unity 排行榜 - Pubnub、Playfab 或 Firebase?

问题描述

我目前正在为我的 Mac OS X Unity 游戏制作排行榜功能。我第一次尝试 Playfab 但我一直收到错误消息“PlayFabException:必须登录才能调用方法 PlayFab”。我找不到解决此问题的方法

我有 2 个执行此操作的脚本,这是 PlayFabmanger 脚本的代码

`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PlayFab;
using PlayFab.ClientModels;
using System;

    public class PlayFabManager : MonoBehavIoUr

    //public static PlayFabManager instance;
    // Start is called before the first frame update
    void Start()
    {
        //instance = this;
        if (string.IsNullOrEmpty(PlayFabSettings.staticSettings.TitleId))
        {
            /*
            Please change the titleId below to your own titleId from PlayFab Game Manager.
            If you have already set the value in the Editor Extensions,this can be skipped.
            */
            PlayFabSettings.staticSettings.TitleId = "F9F3D";
        }
        Login();
    }

    // Update is called once per frame
    void Update()
    {

    }

    void Login()
    {
        var request = new LoginWithCustomIDRequest
        {
            CustomId = SystemInfo.deviceUniqueIdentifier,CreateAccount = true
        };
        PlayFabClientAPI.LoginWithCustomID(request,OnSuccess,OnError);
    }

    //private void OnLoginSuccess(LoginResult result)
    //{
    //    //>> Call Client API here <<
    //    var getStoreItemsRequest = new GetStoreItemsRequest { StoreId = "[YourStoreId]" };// Please change this value to your own storeId from PlayFab Game Manager
    //    PlayFabClientAPI.GetStoreItems(getStoreItemsRequest,OnGetSuccess,OnError);

    //}


    void OnSuccess(LoginResult result)
    {
        print("Successful login create");
    }

    public void SendleaderBoard(int score)
    {
        var request = new UpdatePlayerStatisticsRequest
        {
            Statistics = new List<StatisticUpdate>
            {
                new StatisticUpdate
                {
                    StatisticName = "Platformscore",Value = score
                }
            }
        };
        PlayFabClientAPI.UpdatePlayerStatistics(request,OnleaderboardUpdate,OnError);
    }

    void OnleaderboardUpdate(UpdatePlayerStatisticsResult result)
    {
        print("Successful leaderboard sent");
    }

    void OnError(PlayFabError error)
    {
        print("Error while logging in/creating account!");
        print(error.GenerateErrorReport());
    }

    public void GetleaderBoard()
    {
        var request = new GetleaderboardRequest
        {
            StatisticName = "Platformscore",StartPosition = 0,MaxResultsCount = 10
        };
        PlayFabClientAPI.Getleaderboard(request,OnleaderboardGet,OnError);
    }

    private void OnleaderboardGet(GetleaderboardResult result)
    {
        foreach (var item in result.leaderboard)
        {
            print(item.Position + " " + item.PlayFabId + " " + item.StatValue);
        }
    }

    }

`

我在另一个脚本中还有一行代码,它在 start 方法调用并引用了上面的脚本,我在其中传入了 Playerprefs.GetInt 变量: playFabManager.SendleaderBoard(PlayerPrefs.GetInt("TtlPoints"));

有人对解决错误有任何想法吗?是否有更简单的方法在 Mac OS X 上使用 firebase 或 pubnub 等其他扩展程序实现此排行榜功能

抱歉我的英语不好,期待您的来信。

解决方法

PubNub 很棒,Beamable 将它们用于 Unity 的 fabs 排行榜!检查一下。

,

我会接受 Firebase 的答案。

如果您采用 Firebase 路线,则没有开箱即用的排行榜解决方案。有一个 example open source repository 可用于在实时数据库上实施排行榜,实施起来应该相对简单。

您的第二个问题是,尽管实时数据库确实可以在桌面上运行(尤其是排行榜没有给我带来任何问题),it is currently a beta feature only intended for use during development。如果您提交相关错误,团队将努力修复它,但它可能会优先于任何移动功能。您可以直接使用 REST API 实现这一切,但此时官方 Unity 示例和文档将不适用。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...