mac os x 设备上的 Unity 排行榜 - Pubnub、Playfab 或 Firebase?
Unity leaderboard on mac os x device - Pubnub, Playfab or 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 的晶圆厂排行榜!检查出来。
我会接受 Firebase 的回答。
如果您选择 Firebase 路线,则没有开箱即用的排行榜解决方案。您可以使用 example open source repository 在实时数据库上实施排行榜,实施起来应该相对简单。
你的第二个问题是,虽然实时数据库确实可以在桌面上运行(尤其是排行榜没有给我任何问题),但直接 it is currently a beta feature only intended for use during development. If you file a related bug, the team will work to fix it, but it will probably be prioritized behind any mobile-features. You could implement it all using the REST API,但此时官方Unity 示例和文档将不适用。
我目前正在为我的 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 的晶圆厂排行榜!检查出来。
我会接受 Firebase 的回答。
如果您选择 Firebase 路线,则没有开箱即用的排行榜解决方案。您可以使用 example open source repository 在实时数据库上实施排行榜,实施起来应该相对简单。
你的第二个问题是,虽然实时数据库确实可以在桌面上运行(尤其是排行榜没有给我任何问题),但直接 it is currently a beta feature only intended for use during development. If you file a related bug, the team will work to fix it, but it will probably be prioritized behind any mobile-features. You could implement it all using the REST API,但此时官方Unity 示例和文档将不适用。