using System.Collections;
using System.Collections.Generic;
using Touka.GameLogic;
using UnityEngine;
using UnityEngine.SocialPlatforms;
///
/// Game Center 排行榜类
///
/// 1. 初始化 init;(StaticOtherConfig 里LeaderBoard_Switch开关打开,自动调用)
/// 2. 上报分数 ReportScore;(分数,排行榜ID)
/// 3. 显示排行榜 ShowLeaderboard;
///
public class LeaderBoards : ToukaSingletonMonoBehaviour
{
//public string leaderBoardId = "BossFightScore";
///
/// 初始化
///
public void init()
{
AuthenticateToGameCenter();
}
///
/// 登录Game Center
///
private bool isAuthenticatedToGameCenter;
public void AuthenticateToGameCenter()
{
#if UNITY_IPHONE && !UNITY_EDITOR
Social.localUser.Authenticate(success =>
{
if (success)
{
Debug.Log("[LeaderBoards] Authentication successful");
}
else
{
Debug.Log("[LeaderBoards] Authentication failed");
}
});
#endif
}
///
/// 上报分数到Game Center
///
/// 分数
/// 排行榜ID (Appstore后台创建的)
public void ReportScore(long score, string leaderboardID)
{
#if UNITY_IPHONE && !UNITY_EDITOR
Debug.Log("Reporting score " + score + " on leaderboard " + leaderboardID);
Social.ReportScore(score, leaderboardID, success =>
{
if (success)
{
Debug.Log("[LeaderBoards] Reported score successfully");
}
else
{
Debug.Log("[LeaderBoards] Failed to report score");
}
});
#endif
}
///
/// 展示排行榜
///
public void ShowLeaderboard()
{
#if UNITY_IPHONE && !UNITY_EDITOR
Social.ShowLeaderboardUI();
#endif
}
}