PlayGamesScore.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // <copyright file="PlayGamesScore.cs" company="Google Inc.">
  2. // Copyright (C) 2014 Google Inc.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. // </copyright>
  16. #if (UNITY_ANDROID || (UNITY_IPHONE && !NO_GPGS))
  17. namespace GooglePlayGames
  18. {
  19. using System;
  20. using UnityEngine.SocialPlatforms;
  21. /// <summary>
  22. /// Represents a Google Play Games score that can be sent to a leaderboard.
  23. /// </summary>
  24. public class PlayGamesScore : IScore
  25. {
  26. private string mLbId = null;
  27. private long mValue = 0;
  28. private ulong mRank = 0;
  29. private string mPlayerId = string.Empty;
  30. private string mMetadata = string.Empty;
  31. private DateTime mDate = new DateTime(1970, 1, 1, 0, 0, 0);
  32. internal PlayGamesScore(DateTime date, string leaderboardId,
  33. ulong rank, string playerId, ulong value, string metadata)
  34. {
  35. this.mDate = date;
  36. mLbId = leaderboardID;
  37. this.mRank = rank;
  38. this.mPlayerId = playerId;
  39. this.mValue = (long)value;
  40. this.mMetadata = metadata;
  41. }
  42. /// <summary>
  43. /// Reports the score. Equivalent to <see cref="PlayGamesPlatform.ReportScore" />.
  44. /// </summary>
  45. public void ReportScore(Action<bool> callback)
  46. {
  47. PlayGamesPlatform.Instance.ReportScore(mValue, mLbId, mMetadata, callback);
  48. }
  49. /// <summary>
  50. /// Gets or sets the leaderboard id.
  51. /// </summary>
  52. /// <returns>
  53. /// The leaderboard id.
  54. /// </returns>
  55. public string leaderboardID
  56. {
  57. get
  58. {
  59. return mLbId;
  60. }
  61. set
  62. {
  63. mLbId = value;
  64. }
  65. }
  66. /// <summary>
  67. /// Gets or sets the score value.
  68. /// </summary>
  69. /// <returns>
  70. /// The value.
  71. /// </returns>
  72. public long value
  73. {
  74. get
  75. {
  76. return mValue;
  77. }
  78. set
  79. {
  80. mValue = value;
  81. }
  82. }
  83. /// <summary>
  84. /// Not implemented. Returns Jan 01, 1970, 00:00:00
  85. /// </summary>
  86. public DateTime date
  87. {
  88. get
  89. {
  90. return mDate;
  91. }
  92. }
  93. /// <summary>
  94. /// Not implemented. Returns the value converted to a string, unformatted.
  95. /// </summary>
  96. public string formattedValue
  97. {
  98. get
  99. {
  100. return mValue.ToString();
  101. }
  102. }
  103. /// <summary>
  104. /// Not implemented. Returns the empty string.
  105. /// </summary>
  106. public string userID
  107. {
  108. get
  109. {
  110. return mPlayerId;
  111. }
  112. }
  113. /// <summary>
  114. /// Not implemented. Returns 1.
  115. /// </summary>
  116. public int rank
  117. {
  118. get
  119. {
  120. return (int)mRank;
  121. }
  122. }
  123. /// <summary>
  124. /// Gets the metaData (scoreTag).
  125. /// </summary>
  126. /// <returns>
  127. /// The metaData.
  128. /// </returns>
  129. public string metaData
  130. {
  131. get
  132. {
  133. return mMetadata;
  134. }
  135. }
  136. }
  137. }
  138. #endif