using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_IPHONE || UNITY_IOS
using UnityEngine.SocialPlatforms.GameCenter;
#endif
namespace Coolape
{
public class CLGameCenter
{
public static bool authenticated = false;
public static string userInfo = "";
///
/// 初始化 GameCenter 登陆
///
public static void authenticate (object callback, object orgs)
{
#if UNITY_IPHONE|| UNITY_IOS
Social.localUser.Authenticate (success => {
if (success) {
authenticated = Social.localUser.authenticated;
Debug.Log ("Authentication successful");
Hashtable m = new Hashtable ();
m ["Username"] = Social.localUser.userName;
m ["UserID"] = Social.localUser.id;
m ["IsUnderage"] = Social.localUser.underage;
m ["state"] = Social.localUser.state.ToString ();
userInfo = JSON.JsonEncode (m);
Debug.Log (userInfo);
Utl.doCallback (callback, success, userInfo, orgs);
} else {
Debug.Log ("Authentication failed");
userInfo = "";
Utl.doCallback (callback, success, userInfo, orgs);
}
});
#endif
}
///
/// Shows the achievements U.打开成就
///
public static void showAchievementsUI ()
{
#if UNITY_IPHONE|| UNITY_IOS
if (Social.localUser.authenticated) {
Social.ShowAchievementsUI ();
} else {
Debug.LogWarning ("Social.localUser.authenticated==" + Social.localUser.authenticated);
}
#endif
}
///
/// Shows the leaderboard U.打开排行榜
///
public static void showLeaderboardUI ()
{
#if UNITY_IPHONE|| UNITY_IOS
if (Social.localUser.authenticated) {
Social.ShowLeaderboardUI ();
} else {
Debug.LogWarning ("Social.localUser.authenticated==" + Social.localUser.authenticated);
}
#endif
}
///
/// Reports the score.排行榜设置分数
///
/// Sore.
/// Board.
/// Callback.
/// Orgs.
public static void reportScore (long sore, string board, object callback, object orgs)
{
#if UNITY_IPHONE|| UNITY_IOS
if (Social.localUser.authenticated) {
Social.ReportScore (sore, board, success => {
Utl.doCallback (callback, success, orgs);
});
} else {
Debug.LogWarning ("Social.localUser.authenticated==" + Social.localUser.authenticated);
Utl.doCallback (callback, false, orgs, "Social.localUser.authenticated==" + Social.localUser.authenticated);
}
#endif
}
///
/// Reports the progress.设置成就
///
/// Active identifier.
/// Progress.
/// Callback.
/// Orgs.
public static void reportProgress (string activeId, double progress, object callback, object orgs)
{
#if UNITY_IPHONE|| UNITY_IOS
if (Social.localUser.authenticated) {
Social.ReportProgress (activeId, progress, success => {
Utl.doCallback (callback, success, orgs);
});
} else {
Debug.LogWarning ("Social.localUser.authenticated==" + Social.localUser.authenticated);
Utl.doCallback (callback, false, orgs, "Social.localUser.authenticated==" + Social.localUser.authenticated);
}
#endif
}
}
}