Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- #if UNITY_ANDROID
- using GooglePlayGames;
- using GooglePlayGames.BasicApi;
- #endif
- public class LeaderBoardController : MonoBehaviour
- {
- public static LeaderBoardController instance;
- public static readonly string[] ms_id = GameInfo.ms_ID;
- void Awake()
- {
- MakeInstance();
- }
- void MakeInstance()
- {
- if (instance != null)
- {
- Destroy(gameObject);
- }
- else
- {
- instance = this;
- DontDestroyOnLoad(gameObject);
- }
- }
- private void Start()
- {
- #if UNITY_ANDROID
- PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
- PlayGamesPlatform.InitializeInstance(config);
- // recommended for debugging:
- PlayGamesPlatform.DebugLogEnabled = true;
- // Activate the Google Play Games platform
- PlayGamesPlatform.Activate();
- //LoginGameCenter();
- #else
- LoginGameCenter();
- #endif
- }
- //Open Leaderboard UI
- public void OpenLeaderboards()
- {
- Debug.Log("Try to call OpenLeaderboards function");
- if (Social.localUser.authenticated)
- {
- Debug.Log("authenticated == true, show leaderboard UI");
- Social.ShowLeaderboardUI();
- }
- else
- {
- Debug.Log("authenticated == false, goi ham login");
- LoginGameCenter();
- }
- }
- //Open Achievements UI
- public void OpenAchivements()
- {
- if (Social.localUser.authenticated)
- {
- Social.ShowAchievementsUI();
- }
- }
- //Method to login GameCenter with current user
- public void LoginGameCenter()
- {
- //Check if does not has account login before
- if (!Social.localUser.authenticated)
- {
- //Start login
- Social.localUser.Authenticate((bool success) =>
- {
- if (success)
- {
- Debug.Log("Login thanh cong nha cu");
- }
- else
- {
- Debug.Log("Can not login. Please input your account to game center.");
- }
- });
- }
- }
- public void ReportScore(int _id, int _value)
- {
- if (Social.localUser.authenticated)
- {
- #if UNITY_IOS
- //IOS submit time dang second
- Social.ReportScore(_value, ms_id[_id], (bool success) => {
- if (success)
- {
- Debug.Log("Changed HighScore of Best Time");
- }
- });
- #else
- //Android submit time dang milisecond
- Social.ReportScore(ms_id[_id],_value, (bool success) =>
- {
- if (success)
- {
- Debug.Log("Changed HighScore of Best Time");
- }
- });
- #endif
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement