PlayGamesScore.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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
  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 { return mLbId; }
  58. set { mLbId = value; }
  59. }
  60. /// <summary>
  61. /// Gets or sets the score value.
  62. /// </summary>
  63. /// <returns>
  64. /// The value.
  65. /// </returns>
  66. public long value
  67. {
  68. get { return mValue; }
  69. set { mValue = value; }
  70. }
  71. /// <summary>
  72. /// Not implemented. Returns Jan 01, 1970, 00:00:00
  73. /// </summary>
  74. public DateTime date
  75. {
  76. get { return mDate; }
  77. }
  78. /// <summary>
  79. /// Not implemented. Returns the value converted to a string, unformatted.
  80. /// </summary>
  81. public string formattedValue
  82. {
  83. get { return mValue.ToString(); }
  84. }
  85. /// <summary>
  86. /// Not implemented. Returns the empty string.
  87. /// </summary>
  88. public string userID
  89. {
  90. get { return mPlayerId; }
  91. }
  92. /// <summary>
  93. /// Not implemented. Returns 1.
  94. /// </summary>
  95. public int rank
  96. {
  97. get { return (int) mRank; }
  98. }
  99. /// <summary>
  100. /// Gets the metaData (scoreTag).
  101. /// </summary>
  102. /// <returns>
  103. /// The metaData.
  104. /// </returns>
  105. public string metaData
  106. {
  107. get { return mMetadata; }
  108. }
  109. }
  110. }
  111. #endif