Achievement.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. // <copyright file="Achievement.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.BasicApi
  18. {
  19. using System;
  20. /// <summary>Data interface for retrieving achievement information.</summary>
  21. /// <remarks>
  22. /// There are 3 states an achievement can be in:
  23. /// <para>
  24. /// Hidden - indicating the name and description of the achievement is
  25. /// not visible to the player.
  26. /// </para><para>
  27. /// Revealed - indicating the name and description of the achievement is
  28. /// visible to the player.
  29. /// Unlocked - indicating the player has unlocked, or achieved, the achievment.
  30. /// </para><para>
  31. /// Achievements has two types, standard which is unlocked in one step,
  32. /// and incremental, which require multiple steps to unlock.
  33. /// </para>
  34. /// </remarks>
  35. public class Achievement
  36. {
  37. static readonly DateTime UnixEpoch =
  38. new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
  39. private string mId = string.Empty;
  40. private bool mIsIncremental = false;
  41. private bool mIsRevealed = false;
  42. private bool mIsUnlocked = false;
  43. private int mCurrentSteps = 0;
  44. private int mTotalSteps = 0;
  45. private string mDescription = string.Empty;
  46. private string mName = string.Empty;
  47. private long mLastModifiedTime = 0;
  48. private ulong mPoints;
  49. private string mRevealedImageUrl;
  50. private string mUnlockedImageUrl;
  51. /// <summary>
  52. /// Returns a <see cref="System.String"/> that represents the current <see cref="GooglePlayGames.BasicApi.Achievement"/>.
  53. /// </summary>
  54. /// <returns>A <see cref="System.String"/> that represents the current <see cref="GooglePlayGames.BasicApi.Achievement"/>.</returns>
  55. public override string ToString()
  56. {
  57. return string.Format(
  58. "[Achievement] id={0}, name={1}, desc={2}, type={3}, revealed={4}, unlocked={5}, steps={6}/{7}",
  59. mId, mName, mDescription, mIsIncremental ? "INCREMENTAL" : "STANDARD",
  60. mIsRevealed, mIsUnlocked, mCurrentSteps, mTotalSteps);
  61. }
  62. public Achievement()
  63. {
  64. }
  65. /// <summary>
  66. /// Indicates whether this achievement is incremental.
  67. /// </summary>
  68. public bool IsIncremental
  69. {
  70. get { return mIsIncremental; }
  71. set { mIsIncremental = value; }
  72. }
  73. /// <summary>
  74. /// The number of steps the user has gone towards unlocking this achievement.
  75. /// </summary>
  76. public int CurrentSteps
  77. {
  78. get { return mCurrentSteps; }
  79. set { mCurrentSteps = value; }
  80. }
  81. /// <summary>
  82. /// The total number of steps needed to unlock this achievement.
  83. /// </summary>
  84. public int TotalSteps
  85. {
  86. get { return mTotalSteps; }
  87. set { mTotalSteps = value; }
  88. }
  89. /// <summary>
  90. /// Indicates whether the achievement is unlocked or not.
  91. /// </summary>
  92. public bool IsUnlocked
  93. {
  94. get { return mIsUnlocked; }
  95. set { mIsUnlocked = value; }
  96. }
  97. /// <summary>
  98. /// Indicates whether the achievement is revealed or not (hidden).
  99. /// </summary>
  100. public bool IsRevealed
  101. {
  102. get { return mIsRevealed; }
  103. set { mIsRevealed = value; }
  104. }
  105. /// <summary>
  106. /// The ID string of this achievement.
  107. /// </summary>
  108. public string Id
  109. {
  110. get { return mId; }
  111. set { mId = value; }
  112. }
  113. /// <summary>
  114. /// The description of this achievement.
  115. /// </summary>
  116. public string Description
  117. {
  118. get { return this.mDescription; }
  119. set { mDescription = value; }
  120. }
  121. /// <summary>
  122. /// The name of this achievement.
  123. /// </summary>
  124. public string Name
  125. {
  126. get { return this.mName; }
  127. set { mName = value; }
  128. }
  129. /// <summary>
  130. /// The date and time the state of the achievement was modified.
  131. /// </summary>
  132. /// <remarks>
  133. /// The value is invalid (-1 long) if the achievement state has
  134. /// never been updated.
  135. /// </remarks>
  136. public DateTime LastModifiedTime
  137. {
  138. get { return UnixEpoch.AddMilliseconds(mLastModifiedTime); }
  139. set
  140. {
  141. TimeSpan ts = value - UnixEpoch;
  142. mLastModifiedTime = (long) ts.TotalMilliseconds;
  143. }
  144. }
  145. /// <summary>
  146. /// The number of experience points earned for unlocking this Achievement.
  147. /// </summary>
  148. public ulong Points
  149. {
  150. get { return mPoints; }
  151. set { mPoints = value; }
  152. }
  153. /// <summary>
  154. /// The URL to the image to display when the achievement is revealed.
  155. /// </summary>
  156. public string RevealedImageUrl
  157. {
  158. get { return mRevealedImageUrl; }
  159. set { mRevealedImageUrl = value; }
  160. }
  161. /// <summary>
  162. /// The URL to the image to display when the achievement is unlocked.
  163. /// </summary>
  164. public string UnlockedImageUrl
  165. {
  166. get { return mUnlockedImageUrl; }
  167. set { mUnlockedImageUrl = value; }
  168. }
  169. }
  170. }
  171. #endif