LeaderboardScoreData.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // <copyright file="LeaderboardScoreData.cs" company="Google Inc.">
  2. // Copyright (C) 2015 Google Inc. All Rights Reserved.
  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.Collections.Generic;
  20. using UnityEngine.SocialPlatforms;
  21. /// <summary>
  22. /// Leaderboard score data. This is the callback data
  23. /// when loading leaderboard scores. There are several SDK
  24. /// API calls needed to be made to collect all the required data,
  25. /// so this class is used to simplify the response.
  26. /// </summary>
  27. public class LeaderboardScoreData
  28. {
  29. private string mId;
  30. private ResponseStatus mStatus;
  31. private ulong mApproxCount;
  32. private string mTitle;
  33. private IScore mPlayerScore;
  34. private ScorePageToken mPrevPage;
  35. private ScorePageToken mNextPage;
  36. private List<PlayGamesScore> mScores = new List<PlayGamesScore>();
  37. internal LeaderboardScoreData(string leaderboardId)
  38. {
  39. mId = leaderboardId;
  40. }
  41. internal LeaderboardScoreData(string leaderboardId, ResponseStatus status)
  42. {
  43. mId = leaderboardId;
  44. mStatus = status;
  45. }
  46. public bool Valid
  47. {
  48. get
  49. {
  50. return mStatus == ResponseStatus.Success ||
  51. mStatus == ResponseStatus.SuccessWithStale;
  52. }
  53. }
  54. public ResponseStatus Status
  55. {
  56. get { return mStatus; }
  57. internal set { mStatus = value; }
  58. }
  59. public ulong ApproximateCount
  60. {
  61. get { return mApproxCount; }
  62. internal set { mApproxCount = value; }
  63. }
  64. public string Title
  65. {
  66. get { return mTitle; }
  67. internal set { mTitle = value; }
  68. }
  69. public string Id
  70. {
  71. get { return mId; }
  72. internal set { mId = value; }
  73. }
  74. public IScore PlayerScore
  75. {
  76. get { return mPlayerScore; }
  77. internal set { mPlayerScore = value; }
  78. }
  79. public IScore[] Scores
  80. {
  81. get { return mScores.ToArray(); }
  82. }
  83. internal int AddScore(PlayGamesScore score)
  84. {
  85. mScores.Add(score);
  86. return mScores.Count;
  87. }
  88. public ScorePageToken PrevPageToken
  89. {
  90. get { return mPrevPage; }
  91. internal set { mPrevPage = value; }
  92. }
  93. public ScorePageToken NextPageToken
  94. {
  95. get { return mNextPage; }
  96. internal set { mNextPage = value; }
  97. }
  98. public override string ToString()
  99. {
  100. return string.Format("[LeaderboardScoreData: mId={0}, " +
  101. " mStatus={1}, mApproxCount={2}, mTitle={3}]",
  102. mId, mStatus, mApproxCount, mTitle);
  103. }
  104. }
  105. }
  106. #endif