Achievement.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 || (UNITY_IPHONE && !NO_GPGS))
  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
  71. {
  72. return mIsIncremental;
  73. }
  74. set
  75. {
  76. mIsIncremental = value;
  77. }
  78. }
  79. /// <summary>
  80. /// The number of steps the user has gone towards unlocking this achievement.
  81. /// </summary>
  82. public int CurrentSteps
  83. {
  84. get
  85. {
  86. return mCurrentSteps;
  87. }
  88. set
  89. {
  90. mCurrentSteps = value;
  91. }
  92. }
  93. /// <summary>
  94. /// The total number of steps needed to unlock this achievement.
  95. /// </summary>
  96. public int TotalSteps
  97. {
  98. get
  99. {
  100. return mTotalSteps;
  101. }
  102. set
  103. {
  104. mTotalSteps = value;
  105. }
  106. }
  107. /// <summary>
  108. /// Indicates whether the achievement is unlocked or not.
  109. /// </summary>
  110. public bool IsUnlocked
  111. {
  112. get
  113. {
  114. return mIsUnlocked;
  115. }
  116. set
  117. {
  118. mIsUnlocked = value;
  119. }
  120. }
  121. /// <summary>
  122. /// Indicates whether the achievement is revealed or not (hidden).
  123. /// </summary>
  124. public bool IsRevealed
  125. {
  126. get
  127. {
  128. return mIsRevealed;
  129. }
  130. set
  131. {
  132. mIsRevealed = value;
  133. }
  134. }
  135. /// <summary>
  136. /// The ID string of this achievement.
  137. /// </summary>
  138. public string Id
  139. {
  140. get
  141. {
  142. return mId;
  143. }
  144. set
  145. {
  146. mId = value;
  147. }
  148. }
  149. /// <summary>
  150. /// The description of this achievement.
  151. /// </summary>
  152. public string Description
  153. {
  154. get
  155. {
  156. return this.mDescription;
  157. }
  158. set
  159. {
  160. mDescription = value;
  161. }
  162. }
  163. /// <summary>
  164. /// The name of this achievement.
  165. /// </summary>
  166. public string Name
  167. {
  168. get
  169. {
  170. return this.mName;
  171. }
  172. set
  173. {
  174. mName = value;
  175. }
  176. }
  177. /// <summary>
  178. /// The date and time the state of the achievement was modified.
  179. /// </summary>
  180. /// <remarks>
  181. /// The value is invalid (-1 long) if the achievement state has
  182. /// never been updated.
  183. /// </remarks>
  184. public DateTime LastModifiedTime
  185. {
  186. get
  187. {
  188. return UnixEpoch.AddMilliseconds(mLastModifiedTime);
  189. }
  190. set
  191. {
  192. TimeSpan ts = value - UnixEpoch;
  193. mLastModifiedTime = (long)ts.TotalMilliseconds;
  194. }
  195. }
  196. /// <summary>
  197. /// The number of experience points earned for unlocking this Achievement.
  198. /// </summary>
  199. public ulong Points
  200. {
  201. get
  202. {
  203. return mPoints;
  204. }
  205. set
  206. {
  207. mPoints = value;
  208. }
  209. }
  210. /// <summary>
  211. /// The URL to the image to display when the achievement is revealed.
  212. /// </summary>
  213. public string RevealedImageUrl
  214. {
  215. get
  216. {
  217. return mRevealedImageUrl;
  218. }
  219. set
  220. {
  221. mRevealedImageUrl = value;
  222. }
  223. }
  224. /// <summary>
  225. /// The URL to the image to display when the achievement is unlocked.
  226. /// </summary>
  227. public string UnlockedImageUrl
  228. {
  229. get
  230. {
  231. return mUnlockedImageUrl;
  232. }
  233. set
  234. {
  235. mUnlockedImageUrl = value;
  236. }
  237. }
  238. }
  239. }
  240. #endif