//
// Copyright (C) 2014 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#if UNITY_ANDROID
namespace GooglePlayGames.BasicApi
{
using System;
using System.Collections.Generic;
using UnityEngine.SocialPlatforms;
///
/// Defines an abstract interface for a Play Games Client.
///
/// Concrete implementations
/// might be, for example, the client for Android or for iOS. One fundamental concept
/// that implementors of this class must adhere to is stable authentication state.
/// This means that once Authenticate() returns true through its callback, the user is
/// considered to be forever after authenticated while the app is running. The implementation
/// must make sure that this is the case -- for example, it must try to silently
/// re-authenticate the user if authentication is lost or wait for the authentication
/// process to get fixed if it is temporarily in a bad state (such as when the
/// Activity in Android has just been brought to the foreground and the connection to
/// the Games services hasn't yet been established). To the user of this
/// interface, once the user is authenticated, they're forever authenticated.
/// Unless, of course, there is an unusual permanent failure such as the underlying
/// service dying, in which it's acceptable that API method calls will fail.
///
/// All methods can be called from the game thread. The user of this interface
/// DOES NOT NEED to call them from the UI thread of the game. Transferring to the UI
/// thread when necessary is a responsibility of the implementors of this interface.
///
/// CALLBACKS: all callbacks must be invoked in Unity's main thread.
/// Implementors of this interface must guarantee that (suggestion: use
/// ).
///
public interface IPlayGamesClient
{
///
/// Returns the result of the automatic sign-in attempt.
///
/// This returns the result
///
/// Callback
void Authenticate(Action callback);
///
/// Manually requests that your game performs sign in with Play Games Services.
///
///
/// Note that a sign-in attempt will be made automatically when your game's application
/// started. For this reason most games will not need to manually request to perform sign-in
/// unless the automatic sign-in attempt failed and your game requires access to Play Games
/// Services.
///
///
void ManuallyAuthenticate(Action callback);
///
/// Returns whether or not user is authenticated.
///
/// true if the user is authenticated; otherwise, false.
bool IsAuthenticated();
///
/// Requests server-side access to Player Games Services for the currently signed in player.
///
/// When requested an authorization code is returned that can be used by your game-server to
/// exchange for an access token and conditionally a refresh token (when forceRefreshToken
/// is true). The access token may then be used by your game-server to access the Play Games
/// Services web APIs. This is commonly used to complete a sign-in flow by verifying the Play Games
/// Services player id.
///
/// If forceRefreshToken is true, when exchanging the authorization code a refresh token
/// will be returned in addition to the access token. The refresh token allows the game-server to
/// request additional access tokens, allowing your game-server to continue accesses Play Games
/// Services while the user is not actively playing your app.
/// If true when the returned authorization code is exchanged a
/// refresh token will be included in addition to an access token.
///
void RequestServerSideAccess(bool forceRefreshToken, Action callback);
///
/// Requests server-side access to Play Games Services for the currently signed in player.
///
/// An authorization code is returned when requested. Your server can then exchange this code
/// for an access token (and conditionally a refresh token when forceRefreshToken is
/// true). The access token allows your server to access the Play Games Services web APIs, which
/// is often used to complete sign-in by verifying the Play Games Services player ID.
///
/// When forceRefreshToken is true during authorization code exchange, a refresh
/// token is provided along with the access token. This refresh token enables your server to obtain
/// new access tokens and continue accessing Play Games Services even when the user isn't actively
/// playing. Note that refresh tokens are only generated for players who have auto sign-in setting
/// enabled.
///
/// Scopes represent the {@link AuthScope} values requested such as AuthScope.EMAIL,
/// AuthScope.PROFILE, AuthScope.OPEN_ID. For new permissions, users will see a
/// consent screen upon the first request. Granting consent (or if permissions were already
/// granted) results in the {@link AuthResponse} listing the effectively granted {@link AuthScope}.
/// Declining permission results in an empty list of granted {@link AuthScope} in the {@link
/// AuthResponse} . Regardless of granted permissions, a successful request will always return the
/// authorization code.
/// If true when the returned authorization code is exchanged a
/// refresh token will be included in addition to an access token.
///A list of {@link AuthScope} values representing the OAuth 2.0 permissions being
///requested, such as AuthScope.EMAIL, AuthScope.PROFILE and
/// AuthScope.OPEN_ID.
///
/// A {@link Task} that completes with an {@link AuthResponse} containing the OAuth 2.0
/// authorization code as a string and a list of the {@link AuthScope}s that were effectively
/// granted by the user (see description for details on consent). This authorization code can
/// be exchanged by your server for an access token (and conditionally a refresh token) that
/// can be used to access the Play Games Services web APIs and other Google Identity APIs.
void RequestServerSideAccess(bool forceRefreshToken, List scopes, Action callback);
///
/// Requests Recall Access to Player Games Services for the currently signed in account
///
/// When requested a session id is returned that can be used by your game-server to
/// use Recall Access APIs like LinkPerson , UnlinkPersona and get Details about Recall Tokens
/// and corresponding personas. See https://developer.android.com/games/pgs/recall?hl=en.
///
///
///
///
///
void RequestRecallAccessToken(Action callback);
///
/// Returns the authenticated user's ID. Note that this value may change if a user signs
/// out and signs in with a different account.
///
/// The user's ID, null if the user is not logged in.
string GetUserId();
///
/// Loads friends of the authenticated user. This loads the entire list of friends.
///
/// Callback invoked when complete. bool argument
/// indicates success.
void LoadFriends(Action callback);
///
/// Returns a human readable name for the user, if they are logged in.
///
/// The user's human-readable name. null if they are not logged
/// in
string GetUserDisplayName();
///
/// Returns the user's avatar url, if they are logged in and have an avatar.
///
/// The URL to load the avatar image. null if they are not logged
/// in
string GetUserImageUrl();
/// Gets the player stats.
/// Callback for response.
void GetPlayerStats(Action callback);
///
/// Loads the users specified. This is mainly used by the leaderboard
/// APIs to get the information of a high scorer.
///
/// User identifiers.
/// Callback.
void LoadUsers(string[] userIds, Action callback);
///
/// Loads the achievements for the current signed in user and invokes
/// the callback.
///
void LoadAchievements(Action callback);
///
/// Unlocks the achievement with the passed identifier.
///
/// If the operation succeeds, the callback
/// will be invoked on the game thread with true. If the operation fails, the
/// callback will be invoked with false. This operation will immediately fail if
/// the user is not authenticated (i.e. the callback will immediately be invoked with
/// false). If the achievement is already unlocked, this call will
/// succeed immediately.
///
/// The ID of the achievement to unlock.
/// Callback used to indicate whether the operation
/// succeeded or failed.
void UnlockAchievement(string achievementId, Action successOrFailureCalllback);
///
/// Reveals the achievement with the passed identifier.
///
/// If the operation succeeds, the callback
/// will be invoked on the game thread with true. If the operation fails, the
/// callback will be invoked with false. This operation will immediately fail if
/// the user is not authenticated (i.e. the callback will immediately be invoked with
/// false). If the achievement is already in a revealed state, this call will
/// succeed immediately.
///
/// The ID of the achievement to reveal.
/// Callback used to indicate whether the operation
/// succeeded or failed.
void RevealAchievement(string achievementId, Action successOrFailureCalllback);
///
/// Increments the achievement with the passed identifier.
///
/// If the operation succeeds, the
/// callback will be invoked on the game thread with true. If the operation
/// fails, the callback will be invoked with false. This operation will
/// immediately fail if the user is not authenticated (i.e. the callback will immediately be
/// invoked with false).
///
/// The ID of the achievement to increment.
/// The number of steps to increment by.
/// Callback used to indicate whether the operation
/// succeeded or failed.
void IncrementAchievement(string achievementId, int steps,
Action successOrFailureCalllback);
///
/// Set an achievement to have at least the given number of steps completed.
///
///
/// Calling this method while the achievement already has more steps than
/// the provided value is a no-op. Once the achievement reaches the
/// maximum number of steps, the achievement is automatically unlocked,
/// and any further mutation operations are ignored.
///
/// Ach identifier.
/// Steps.
/// Callback.
void SetStepsAtLeast(string achId, int steps, Action callback);
///
/// Shows the appropriate platform-specific achievements UI.
/// The callback to invoke when complete. If null,
/// no callback is called.
///
void ShowAchievementsUI(Action callback);
///
/// Shows the appropriate platform-specific friends sharing UI.
/// The callback to invoke when complete. If null,
/// no callback is called.
///
void AskForLoadFriendsResolution(Action callback);
///
/// Returns the latest LoadFriendsStatus obtained from loading friends.
///
LoadFriendsStatus GetLastLoadFriendsStatus();
///
/// Shows the Play Games Player Profile UI for a specific user identifier.
///
/// User Identifier.
///
/// The game's own display name of the player referred to by userId.
///
///
/// The game's own display name of the current player.
///
/// Callback invoked upon completion.
void ShowCompareProfileWithAlternativeNameHintsUI(
string otherUserId, string otherPlayerInGameName, string currentPlayerInGameName,
Action callback);
///
/// Returns if the user has allowed permission for the game to access the friends list.
///
/// If true, this call will clear any locally cached data and
/// attempt to fetch the latest data from the server. Normally, this should be set to
/// false to gain advantages of data caching. Callback
/// invoked upon completion.
void GetFriendsListVisibility(bool forceReload, Action callback);
///
/// Loads the first page of the user's friends
///
///
/// The number of entries to request for this initial page. Note that if cached
/// data already exists, the returned buffer may contain more than this size, but it is
/// guaranteed to contain at least this many if the collection contains enough records.
///
///
/// If true, this call will clear any locally cached data and attempt to
/// fetch the latest data from the server. This would commonly be used for something like a
/// user-initiated refresh. Normally, this should be set to false to gain advantages
/// of data caching.
/// Callback invoked upon completion.
void LoadFriends(int pageSize, bool forceReload, Action callback);
///
/// Loads the friends list page
///
///
/// The number of entries to request for this page. Note that if cached data already
/// exists, the returned buffer may contain more than this size, but it is guaranteed
/// to contain at least this many if the collection contains enough records.
///
///
void LoadMoreFriends(int pageSize, Action callback);
///
/// Shows the leaderboard UI for a specific leaderboard.
///
/// If the passed ID is null, all leaderboards are displayed.
///
/// The leaderboard to display. null to display
/// all.
/// Timespan to display for the leaderboard
/// If non-null, the callback to invoke when the
/// leaderboard is dismissed.
///
void ShowLeaderboardUI(string leaderboardId, LeaderboardTimeSpan span,
Action callback);
///
/// Loads the score data for the given leaderboard.
///
/// Leaderboard identifier.
/// Start indicating the top scores or player centric
/// max number of scores to return. non-positive indicates
/// no rows should be returned. This causes only the summary info to
/// be loaded. This can be limited
/// by the SDK.
/// leaderboard collection: public or social
/// leaderboard timespan
/// callback with the scores, and a page token.
/// The token can be used to load next/prev pages.
void LoadScores(string leaderboardId, LeaderboardStart start, int rowCount,
LeaderboardCollection collection, LeaderboardTimeSpan timeSpan,
Action callback);
///
/// Loads the more scores for the leaderboard.
///
/// The token is accessed
/// by calling LoadScores() with a positive row count.
///
/// Token for tracking the score loading.
/// max number of scores to return.
/// This can be limited by the SDK.
/// Callback.
void LoadMoreScores(ScorePageToken token, int rowCount,
Action callback);
///
/// Returns the max number of scores returned per call.
///
/// The max results.
int LeaderboardMaxResults();
///
/// Submits the passed score to the passed leaderboard.
///
/// This operation will immediately fail
/// if the user is not authenticated (i.e. the callback will immediately be invoked with
/// false).
///
/// Leaderboard identifier.
/// Score.
/// Callback used to indicate whether the operation
/// succeeded or failed.
void SubmitScore(string leaderboardId, long score, Action successOrFailureCalllback);
///
/// Submits the score for the currently signed-in player.
///
/// Score.
/// leaderboard id.
/// metadata about the score.
/// Callback upon completion.
void SubmitScore(string leaderboardId, long score, string metadata,
Action successOrFailureCalllback);
///
/// Gets the saved game client.
///
/// The saved game client.
SavedGame.ISavedGameClient GetSavedGameClient();
///
/// Gets the events client.
///
/// The events client.
Events.IEventsClient GetEventsClient();
IUserProfile[] GetFriends();
}
}
#endif