Advertisement
loyddskull

Untitled

Feb 17th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. #if UNITY_ANDROID
  4. using GooglePlayGames;
  5. using GooglePlayGames.BasicApi;
  6. #endif
  7.  
  8. public class LeaderBoardController : MonoBehaviour
  9. {
  10. public static LeaderBoardController instance;
  11. public static readonly string[] ms_id = GameInfo.ms_ID;
  12.  
  13. void Awake()
  14. {
  15. MakeInstance();
  16. }
  17.  
  18. void MakeInstance()
  19. {
  20. if (instance != null)
  21. {
  22. Destroy(gameObject);
  23. }
  24. else
  25. {
  26. instance = this;
  27. DontDestroyOnLoad(gameObject);
  28. }
  29. }
  30.  
  31. private void Start()
  32. {
  33. #if UNITY_ANDROID
  34. PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
  35. PlayGamesPlatform.InitializeInstance(config);
  36. // recommended for debugging:
  37. PlayGamesPlatform.DebugLogEnabled = true;
  38. // Activate the Google Play Games platform
  39. PlayGamesPlatform.Activate();
  40.  
  41. //LoginGameCenter();
  42. #else
  43. LoginGameCenter();
  44. #endif
  45. }
  46.  
  47. //Open Leaderboard UI
  48. public void OpenLeaderboards()
  49. {
  50. Debug.Log("Try to call OpenLeaderboards function");
  51. if (Social.localUser.authenticated)
  52. {
  53. Debug.Log("authenticated == true, show leaderboard UI");
  54. Social.ShowLeaderboardUI();
  55. }
  56. else
  57. {
  58. Debug.Log("authenticated == false, goi ham login");
  59. LoginGameCenter();
  60. }
  61. }
  62.  
  63. //Open Achievements UI
  64. public void OpenAchivements()
  65. {
  66. if (Social.localUser.authenticated)
  67. {
  68. Social.ShowAchievementsUI();
  69. }
  70. }
  71.  
  72. //Method to login GameCenter with current user
  73. public void LoginGameCenter()
  74. {
  75. //Check if does not has account login before
  76. if (!Social.localUser.authenticated)
  77. {
  78. //Start login
  79. Social.localUser.Authenticate((bool success) =>
  80. {
  81. if (success)
  82. {
  83. Debug.Log("Login thanh cong nha cu");
  84. }
  85. else
  86. {
  87. Debug.Log("Can not login. Please input your account to game center.");
  88. }
  89. });
  90. }
  91. }
  92.  
  93.  
  94. public void ReportScore(int _id, int _value)
  95. {
  96. if (Social.localUser.authenticated)
  97. {
  98. #if UNITY_IOS
  99. //IOS submit time dang second
  100. Social.ReportScore(_value, ms_id[_id], (bool success) => {
  101. if (success)
  102. {
  103. Debug.Log("Changed HighScore of Best Time");
  104. }
  105. });
  106. #else
  107.  
  108. //Android submit time dang milisecond
  109. Social.ReportScore(ms_id[_id],_value, (bool success) =>
  110. {
  111. if (success)
  112. {
  113. Debug.Log("Changed HighScore of Best Time");
  114. }
  115. });
  116.  
  117. #endif
  118.  
  119. }
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement