//
// 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 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
{
///
/// Starts the authentication process.
///
/// If silent == true, no UIs will be shown
/// (if UIs are needed, it will fail rather than show them). If silent == false,
/// this may show UIs, consent dialogs, etc.
/// At the end of the process, callback will be invoked to notify of the result.
/// Once the callback returns true, the user is considered to be authenticated
/// forever after.
///
/// If set to true silent.
/// Callback
void Authenticate(bool silent, Action callback);
///
/// Returns whether or not user is authenticated.
///
/// true if the user is authenticated; otherwise, false.
bool IsAuthenticated();
///
/// Signs the user out.
///
void SignOut();
///
/// Returns the authenticated user's ID. Note that this value may change if a user signs
/// on 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 an id token, which can be verified server side, if they are logged in.
///
string GetIdToken();
///
/// The server auth code for this client.
///
///
/// Note: This function is currently only implemented for Android.
///
string GetServerAuthCode();
///
/// Gets another server auth code.
///
/// This method should be called after authenticating, and exchanging
/// the initial server auth code for a token. This is implemented by signing in
/// silently, which if successful returns almost immediately and with a new
/// server auth code.
///
/// Calls Authenticate if needed when
/// retrieving another auth code.
/// Callback returning the auth code, or null if there
/// was a problem. NOTE: This callback can be called immediately.
void GetAnotherServerAuthCode(bool reAuthenticateIfNeeded,
Action callback);
///
/// Gets the user's email.
///
/// The email address returned is selected by the user from the accounts present
/// on the device. There is no guarantee this uniquely identifies the player.
/// For unique identification use the id property of the local player.
/// The user can also choose to not select any email address, meaning it is not
/// available.
///
/// The user email or null if not authenticated or the permission is
/// not available.
string GetUserEmail();
///
/// 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 {@code
/// 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 {@code 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);
///
/// Asks user to give permissions for the given scopes.
///
/// list of scopes to ask permission for
/// Callback used to indicate the outcome of the operation.
void RequestPermissions(string[] scopes, Action callback);
///
/// Returns whether or not user has given permissions for given scopes
///
///
/// list of scopes
/// true, if given, false otherwise.
bool HasPermissions(string[] scopes);
///
/// Gets the saved game client.
///
/// The saved game client.
SavedGame.ISavedGameClient GetSavedGameClient();
///
/// Gets the events client.
///
/// The events client.
Events.IEventsClient GetEventsClient();
///
/// Gets the video client.
///
/// The video client.
Video.IVideoClient GetVideoClient();
IUserProfile[] GetFriends();
///
/// Sets the gravity for popups (Android only).
///
/// This can only be called after authentication. It affects
/// popups for achievements and other game services elements.
/// Gravity for the popup.
void SetGravityForPopups(Gravity gravity);
}
}
#endif