DummyClient.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. // <copyright file="DummyClient.cs" company="Google Inc.">
  2. // Copyright (C) 2014 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;
  20. using GooglePlayGames.OurUtils;
  21. using UnityEngine.SocialPlatforms;
  22. /// <summary>
  23. /// Dummy client used in Editor.
  24. /// </summary>
  25. /// <remarks>Google Play Game Services are not supported in the Editor
  26. /// environment, so this client is used as a placeholder.
  27. /// </remarks>
  28. public class DummyClient : IPlayGamesClient
  29. {
  30. /// <summary>
  31. /// Starts the authentication process.
  32. /// </summary>
  33. /// <remarks> If silent == true, no UIs will be shown
  34. /// (if UIs are needed, it will fail rather than show them). If silent == false,
  35. /// this may show UIs, consent dialogs, etc.
  36. /// At the end of the process, callback will be invoked to notify of the result.
  37. /// Once the callback returns true, the user is considered to be authenticated
  38. /// forever after.
  39. /// </remarks>
  40. /// <param name="callback">Callback when completed.</param>
  41. /// <param name="silent">If set to <c>true</c> silent.</param>
  42. public void Authenticate(bool silent, Action<SignInStatus> callback)
  43. {
  44. LogUsage();
  45. if (callback != null)
  46. {
  47. callback(SignInStatus.Failed);
  48. }
  49. }
  50. /// <summary>
  51. /// Returns whether or not user is authenticated.
  52. /// </summary>
  53. /// <returns>true if authenticated</returns>
  54. /// <c>false</c>
  55. public bool IsAuthenticated()
  56. {
  57. LogUsage();
  58. return false;
  59. }
  60. /// <summary>
  61. /// Signs the user out.
  62. /// </summary>
  63. public void SignOut()
  64. {
  65. LogUsage();
  66. }
  67. /// <summary>
  68. /// Retrieves an id token, which can be verified server side, if they are logged in.
  69. /// </summary>
  70. /// <returns>The identifier token.</returns>
  71. public string GetIdToken()
  72. {
  73. LogUsage();
  74. return null;
  75. }
  76. /// <summary>
  77. /// Returns the authenticated user's ID. Note that this value may change if a user signs
  78. /// on and signs in with a different account.
  79. /// </summary>
  80. /// <returns>The user identifier.</returns>
  81. public string GetUserId()
  82. {
  83. LogUsage();
  84. return "DummyID";
  85. }
  86. public string GetServerAuthCode()
  87. {
  88. LogUsage();
  89. return null;
  90. }
  91. public void GetAnotherServerAuthCode(bool reAuthenticateIfNeeded,
  92. Action<string> callback)
  93. {
  94. LogUsage();
  95. callback(null);
  96. }
  97. /// <summary>
  98. /// Gets the user's email.
  99. /// </summary>
  100. /// <remarks>The email address returned is selected by the user from the accounts present
  101. /// on the device. There is no guarantee this uniquely identifies the player.
  102. /// For unique identification use the id property of the local player.
  103. /// The user can also choose to not select any email address, meaning it is not
  104. /// available.</remarks>
  105. /// <returns>The user email or null if not authenticated or the permission is
  106. /// not available.</returns>
  107. public string GetUserEmail()
  108. {
  109. return string.Empty;
  110. }
  111. /// <summary>
  112. /// Gets the player stats.
  113. /// </summary>
  114. /// <param name="callback">Callback for response.</param>
  115. public void GetPlayerStats(Action<CommonStatusCodes, PlayerStats> callback)
  116. {
  117. LogUsage();
  118. callback(CommonStatusCodes.ApiNotConnected, new PlayerStats());
  119. }
  120. /// <summary>
  121. /// Returns a human readable name for the user, if they are logged in.
  122. /// </summary>
  123. /// <returns>The user display name.</returns>
  124. public string GetUserDisplayName()
  125. {
  126. LogUsage();
  127. return "Player";
  128. }
  129. /// <summary>
  130. /// Returns the user's avatar url, if they are logged in and have an avatar.
  131. /// </summary>
  132. /// <returns>The user image URL.</returns>
  133. public string GetUserImageUrl()
  134. {
  135. LogUsage();
  136. return null;
  137. }
  138. /// <summary>
  139. /// Loads the players specified.
  140. /// </summary>
  141. /// <remarks> This is mainly used by the leaderboard
  142. /// APIs to get the information of a high scorer.
  143. /// </remarks>
  144. /// <param name="userIds">User identifiers.</param>
  145. /// <param name="callback">Callback to invoke when completed.</param>
  146. public void LoadUsers(string[] userIds, Action<IUserProfile[]> callback)
  147. {
  148. LogUsage();
  149. if (callback != null)
  150. {
  151. callback.Invoke(null);
  152. }
  153. }
  154. /// <summary>
  155. /// Loads the achievements for the current player.
  156. /// </summary>
  157. /// <param name="callback">Callback to invoke when completed.</param>
  158. public void LoadAchievements(Action<Achievement[]> callback)
  159. {
  160. LogUsage();
  161. if (callback != null)
  162. {
  163. callback.Invoke(null);
  164. }
  165. }
  166. /// <summary>
  167. /// Unlocks the achievement.
  168. /// </summary>
  169. /// <param name="achId">Achievement identifier.</param>
  170. /// <param name="callback">Callback to invoke when complete.</param>
  171. public void UnlockAchievement(string achId, Action<bool> callback)
  172. {
  173. LogUsage();
  174. if (callback != null)
  175. {
  176. callback.Invoke(false);
  177. }
  178. }
  179. /// <summary>
  180. /// Reveals the achievement.
  181. /// </summary>
  182. /// <param name="achId">Achievement identifier.</param>
  183. /// <param name="callback">Callback to invoke when complete.</param>
  184. public void RevealAchievement(string achId, Action<bool> callback)
  185. {
  186. LogUsage();
  187. if (callback != null)
  188. {
  189. callback.Invoke(false);
  190. }
  191. }
  192. /// <summary>
  193. /// Increments the achievement.
  194. /// </summary>
  195. /// <param name="achId">Achievement identifier.</param>
  196. /// <param name="steps">Steps to increment by..</param>
  197. /// <param name="callback">Callback to invoke when complete.</param>
  198. public void IncrementAchievement(string achId, int steps, Action<bool> callback)
  199. {
  200. LogUsage();
  201. if (callback != null)
  202. {
  203. callback.Invoke(false);
  204. }
  205. }
  206. /// <summary>
  207. /// Set an achievement to have at least the given number of steps completed.
  208. /// </summary>
  209. /// <remarks>
  210. /// Calling this method while the achievement already has more steps than
  211. /// the provided value is a no-op. Once the achievement reaches the
  212. /// maximum number of steps, the achievement is automatically unlocked,
  213. /// and any further mutation operations are ignored.
  214. /// </remarks>
  215. /// <param name="achId">Achievement identifier.</param>
  216. /// <param name="steps">Steps to increment to at least.</param>
  217. /// <param name="callback">Callback to invoke when complete.</param>
  218. public void SetStepsAtLeast(string achId, int steps, Action<bool> callback)
  219. {
  220. LogUsage();
  221. if (callback != null)
  222. {
  223. callback.Invoke(false);
  224. }
  225. }
  226. /// <summary>
  227. /// Shows the achievements UI
  228. /// </summary>
  229. /// <param name="callback">Callback to invoke when complete.</param>
  230. public void ShowAchievementsUI(Action<UIStatus> callback)
  231. {
  232. LogUsage();
  233. if (callback != null)
  234. {
  235. callback.Invoke(UIStatus.VersionUpdateRequired);
  236. }
  237. }
  238. public void AskForLoadFriendsResolution(Action<UIStatus> callback) {
  239. LogUsage();
  240. if (callback != null) {
  241. callback.Invoke(UIStatus.VersionUpdateRequired);
  242. }
  243. }
  244. public LoadFriendsStatus GetLastLoadFriendsStatus() {
  245. LogUsage();
  246. return LoadFriendsStatus.Unknown;
  247. }
  248. public void LoadFriends(int pageSize, bool forceReload,
  249. Action<LoadFriendsStatus> callback) {
  250. LogUsage();
  251. if (callback != null) {
  252. callback.Invoke(LoadFriendsStatus.Unknown);
  253. }
  254. }
  255. public void LoadMoreFriends(int pageSize, Action<LoadFriendsStatus> callback) {
  256. LogUsage();
  257. if (callback != null) {
  258. callback.Invoke(LoadFriendsStatus.Unknown);
  259. }
  260. }
  261. public void ShowCompareProfileWithAlternativeNameHintsUI(string userId,
  262. string otherPlayerInGameName,
  263. string currentPlayerInGameName,
  264. Action<UIStatus> callback) {
  265. LogUsage();
  266. if (callback != null) {
  267. callback.Invoke(UIStatus.VersionUpdateRequired);
  268. }
  269. }
  270. public void GetFriendsListVisibility(bool forceReload,
  271. Action<FriendsListVisibilityStatus> callback) {
  272. LogUsage();
  273. if (callback != null) {
  274. callback.Invoke(FriendsListVisibilityStatus.Unknown);
  275. }
  276. }
  277. /// <summary>
  278. /// Shows the leaderboard UI
  279. /// </summary>
  280. /// <param name="leaderboardId">Leaderboard identifier.</param>
  281. /// <param name="span">Timespan to display.</param>
  282. /// <param name="callback">Callback to invoke when complete.</param>
  283. public void ShowLeaderboardUI(
  284. string leaderboardId,
  285. LeaderboardTimeSpan span,
  286. Action<UIStatus> callback)
  287. {
  288. LogUsage();
  289. if (callback != null)
  290. {
  291. callback.Invoke(UIStatus.VersionUpdateRequired);
  292. }
  293. }
  294. /// <summary>
  295. /// Returns the max number of scores returned per call.
  296. /// </summary>
  297. /// <returns>The max results.</returns>
  298. public int LeaderboardMaxResults()
  299. {
  300. return 25;
  301. }
  302. /// <summary>
  303. /// Loads the score data for the given leaderboard.
  304. /// </summary>
  305. /// <param name="leaderboardId">Leaderboard identifier.</param>
  306. /// <param name="start">Start indicating the top scores or player centric</param>
  307. /// <param name="rowCount">Row count.</param>
  308. /// <param name="collection">Collection to display.</param>
  309. /// <param name="timeSpan">Time span.</param>
  310. /// <param name="callback">Callback to invoke when complete.</param>
  311. public void LoadScores(
  312. string leaderboardId,
  313. LeaderboardStart start,
  314. int rowCount,
  315. LeaderboardCollection collection,
  316. LeaderboardTimeSpan timeSpan,
  317. Action<LeaderboardScoreData> callback)
  318. {
  319. LogUsage();
  320. if (callback != null)
  321. {
  322. callback(new LeaderboardScoreData(
  323. leaderboardId,
  324. ResponseStatus.LicenseCheckFailed));
  325. }
  326. }
  327. /// <summary>
  328. /// Loads the more scores for the leaderboard.
  329. /// </summary>
  330. /// <remarks>The token is accessed
  331. /// by calling LoadScores() with a positive row count.
  332. /// </remarks>
  333. /// <param name="token">Token used to start loading scores.</param>
  334. /// <param name="rowCount">Max number of scores to return.
  335. /// This can be limited by the SDK.</param>
  336. /// <param name="callback">Callback to invoke when complete.</param>
  337. public void LoadMoreScores(
  338. ScorePageToken token,
  339. int rowCount,
  340. Action<LeaderboardScoreData> callback)
  341. {
  342. LogUsage();
  343. if (callback != null)
  344. {
  345. callback(new LeaderboardScoreData(
  346. token.LeaderboardId,
  347. ResponseStatus.LicenseCheckFailed));
  348. }
  349. }
  350. /// <summary>
  351. /// Submits the score.
  352. /// </summary>
  353. /// <param name="leaderboardId">Leaderboard identifier.</param>
  354. /// <param name="score">Score to submit.</param>
  355. /// <param name="callback">Callback to invoke when complete.</param>
  356. public void SubmitScore(string leaderboardId, long score, Action<bool> callback)
  357. {
  358. LogUsage();
  359. if (callback != null)
  360. {
  361. callback.Invoke(false);
  362. }
  363. }
  364. /// <summary>
  365. /// Submits the score for the currently signed-in player
  366. /// to the leaderboard associated with a specific id
  367. /// and metadata (such as something the player did to earn the score).
  368. /// </summary>
  369. /// <param name="leaderboardId">Leaderboard identifier.</param>
  370. /// <param name="score">Score value to submit.</param>
  371. /// <param name="metadata">Metadata about the score.</param>
  372. /// <param name="callback">Callback upon completion.</param>
  373. public void SubmitScore(
  374. string leaderboardId,
  375. long score,
  376. string metadata,
  377. Action<bool> callback)
  378. {
  379. LogUsage();
  380. if (callback != null)
  381. {
  382. callback.Invoke(false);
  383. }
  384. }
  385. /// <summary>Asks user to give permissions for the given scopes.</summary>
  386. /// <param name="scopes">Scope to ask permission for</param>
  387. /// <param name="callback">Callback used to indicate the outcome of the operation.</param>
  388. public void RequestPermissions(string[] scopes, Action<SignInStatus> callback)
  389. {
  390. LogUsage();
  391. if (callback != null)
  392. {
  393. callback.Invoke(SignInStatus.Failed);
  394. }
  395. }
  396. /// <summary>Returns whether or not user has given permissions for given scopes.</summary>
  397. /// <seealso cref="GooglePlayGames.BasicApi.IPlayGamesClient.HasPermissions"/>
  398. /// <param name="scopes">array of scopes</param>
  399. /// <returns><c>true</c>, if given, <c>false</c> otherwise.</returns>
  400. public bool HasPermissions(string[] scopes)
  401. {
  402. LogUsage();
  403. return false;
  404. }
  405. /// <summary>
  406. /// Gets the saved game client.
  407. /// </summary>
  408. /// <returns>The saved game client.</returns>
  409. public SavedGame.ISavedGameClient GetSavedGameClient()
  410. {
  411. LogUsage();
  412. return null;
  413. }
  414. /// <summary>
  415. /// Gets the events client.
  416. /// </summary>
  417. /// <returns>The events client.</returns>
  418. public GooglePlayGames.BasicApi.Events.IEventsClient GetEventsClient()
  419. {
  420. LogUsage();
  421. return null;
  422. }
  423. /// <summary>
  424. /// Gets the video client.
  425. /// </summary>
  426. /// <returns>The video client.</returns>
  427. public GooglePlayGames.BasicApi.Video.IVideoClient GetVideoClient()
  428. {
  429. LogUsage();
  430. return null;
  431. }
  432. /// <summary>
  433. /// Load friends of the authenticated user
  434. /// </summary>
  435. /// <param name="callback">Callback invoked when complete. bool argument
  436. /// indicates success.</param>
  437. public void LoadFriends(Action<bool> callback)
  438. {
  439. LogUsage();
  440. callback(false);
  441. }
  442. /// <summary>
  443. /// Gets the friends.
  444. /// </summary>
  445. /// <returns>The friends.</returns>
  446. public IUserProfile[] GetFriends()
  447. {
  448. LogUsage();
  449. return new IUserProfile[0];
  450. }
  451. /// <summary>
  452. /// Sets the gravity for popups (Android only).
  453. /// </summary>
  454. /// <remarks>This can only be called after authentication. It affects
  455. /// popups for achievements and other game services elements.</remarks>
  456. /// <param name="gravity">Gravity for the popup.</param>
  457. public void SetGravityForPopups(Gravity gravity)
  458. {
  459. LogUsage();
  460. }
  461. /// <summary>
  462. /// Logs the usage.
  463. /// </summary>
  464. private static void LogUsage()
  465. {
  466. Logger.d("Received method call on DummyClient - using stub implementation.");
  467. }
  468. }
  469. }
  470. #endif