C# Class GooglePlayGames.PlayGamesPlatform

Provides access to the Google Play Games platform. This is an implementation of UnityEngine.SocialPlatforms.ISocialPlatform. Activate this platform by calling the Activate method, then authenticate by calling the Authenticate method. After authentication completes, you may call the other methods of this class. This is not a complete implementation of the ISocialPlatform interface. Methods lacking an implementation or whose behavior is at variance with the standard are noted as such.
Inheritance: ISocialPlatform
Mostrar archivo Open project: playgameservices/play-games-plugin-for-unity Class Usage Examples

Public Methods

Method Description
Activate ( ) : PlayGamesPlatform

Activates the Play Games platform as the implementation of Social.Active. After calling this method, you can call methods on Social.Active. For example, Social.Active.Authenticate().

AddIdMapping ( string fromId, string toId ) : void

Specifies that the ID fromId should be implicitly replaced by toId on any calls that take a leaderboard or achievement ID.

After a mapping is registered, you can use fromId instead of toId when making a call. For example, the following two snippets are equivalent: ReportProgress("Cfiwjew894_AQ", 100.0, callback); ...is equivalent to: AddIdMapping("super-combo", "Cfiwjew894_AQ"); ReportProgress("super-combo", 100.0, callback);

Authenticate ( string>.Action callback ) : void

Authenticate the local user with the Google Play Games service.

Authenticate ( string>.Action callback, bool silent ) : void

Authenticate the local user with the Google Play Games service.

Authenticate ( Action callback ) : void

Authenticate the local user with the Google Play Games service.

Authenticate ( Action callback, bool silent ) : void

Authenticate the local user with the Google Play Games service.

Authenticate ( ILocalUser unused, string>.Action callback ) : void

Provided for compatibility with ISocialPlatform.

Authenticate ( ILocalUser unused, Action callback ) : void

Provided for compatibility with ISocialPlatform.

CreateAchievement ( ) : IAchievement

Creates an achievement object which may be subsequently used to report an achievement.

CreateLeaderboard ( ) : ILeaderboard

Returns a leaderboard object that can be configured to load scores.

GetAccessToken ( ) : string

Returns an id token for the user.

GetAchievement ( string achievementId ) : GooglePlayGames.BasicApi.Achievement

Returns the achievement corresponding to the passed achievement identifier.

GetApiClient ( ) : IntPtr

Gets pointer to the Google API client.

This is provided as a helper to making additional JNI calls. This connection is initialized and controlled by the underlying SDK.

GetIdToken ( Action idTokenCallback ) : void

Get an id token for the user.

GetLoading ( ILeaderboard board ) : bool

Check if the leaderboard is currently loading.

GetPlayerStats ( PlayerStats>.Action callback ) : void

Gets the player stats.

GetServerAuthCode ( string>.Action callback ) : void

Gets the server auth code.

This code is used by the server application in order to get an oauth token. For how to use this acccess token please see: https://developers.google.com/drive/v2/web/auth/web-server

GetToken ( ) : string

Retrieves a bearer token associated with the current account.

GetUserDisplayName ( ) : string

Returns the user's display name.

GetUserEmail ( ) : string

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.

GetUserEmail ( string>.Action callback ) : void

Gets the user's email with a callback.

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.

GetUserId ( ) : string

Returns the user's Google ID.

GetUserImageUrl ( ) : string

Returns the user's avatar URL if they have one.

IncrementAchievement ( string achievementID, int steps, Action callback ) : void

Increments an achievement. This is a Play Games extension of the ISocialPlatform API.

InitializeInstance ( GooglePlayGames.BasicApi.PlayGamesClientConfiguration configuration ) : void

Initializes the instance of Play Game Services platform.

This creates the singleton instance of the platform. Multiple calls to this method are ignored.

InitializeNearby ( Action callback ) : void

Initializes the nearby connection platform.

This call initializes the nearby connection platform. This is independent of the Play Game Services initialization. Multiple calls to this method are ignored.

IsAuthenticated ( ) : bool

Determines whether the user is authenticated.

LoadAchievementDescriptions ( Action callback ) : void

Loads the Achievement descriptions.

LoadAchievements ( Action callback ) : void

Loads the achievement state for the current user.

LoadFriends ( ILocalUser user, Action callback ) : void

Loads the friends that also play this game. See loadConnectedPlayers.

This is a callback variant of LoadFriends. When completed, the friends list set in the user object, so they can accessed via the friends property as needed.

LoadMoreScores ( GooglePlayGames.BasicApi.ScorePageToken token, int rowCount, Action callback ) : void

Loads more scores.

This is used to load the next "page" of scores.

LoadScores ( ILeaderboard board, Action callback ) : void

Loads the leaderboard based on the constraints in the leaderboard object.

LoadScores ( string leaderboardId, Action callback ) : void

Loads the scores relative the player.

This returns the 25 (which is the max results returned by the SDK per call) scores that are around the player's score on the Public, all time leaderboard. Use the overloaded methods which are specific to GPGS to modify these parameters.

LoadScores ( string leaderboardId, LeaderboardStart start, int rowCount, LeaderboardCollection collection, LeaderboardTimeSpan timeSpan, Action callback ) : void

Loads the scores using the provided parameters.

LoadUsers ( string userIds, Action callback ) : void

Loads the users.

RegisterInvitationDelegate ( InvitationReceivedDelegate deleg ) : void

Register an invitation delegate to be notified when a multiplayer invitation arrives

ReportProgress ( string achievementID, double progress, Action callback ) : void

Reports the progress of an achievement (reveal, unlock or increment). This method attempts to implement the expected behavior of ISocialPlatform.ReportProgress as closely as possible, as described below. Although this method works with incremental achievements for compatibility purposes, calling this method for incremental achievements is not recommended, since the Play Games API exposes incremental achievements in a very different way than the interface presented by ISocialPlatform.ReportProgress. The implementation of this method for incremental achievements attempts to produce the correct result, but may be imprecise. If possible, call IncrementAchievement instead.

ReportScore ( long score, string board, Action callback ) : void

Reports a score to a leaderboard.

ReportScore ( long score, string board, string metadata, Action callback ) : void

Submits the score for the currently signed-in player to the leaderboard associated with a specific id and metadata (such as something the player did to earn the score).

SetDefaultLeaderboardForUI ( string lbid ) : void

Sets the default leaderboard for the leaderboard UI. After calling this method, a call to ShowLeaderboardUI will show only the specified leaderboard instead of showing the list of all leaderboards.

SetStepsAtLeast ( string achievementID, int steps, Action callback ) : void

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.

ShowAchievementsUI ( ) : void

Shows the standard Google Play Games achievements user interface, which allows the player to browse their achievements.

ShowAchievementsUI ( Action callback ) : void

Shows the standard Google Play Games achievements user interface, which allows the player to browse their achievements.

ShowLeaderboardUI ( ) : void

Shows the standard Google Play Games leaderboards user interface, which allows the player to browse their leaderboards. If you have configured a specific leaderboard as the default through a call to SetDefaultLeaderboardForUi, the UI will show that specific leaderboard only. Otherwise, a list of all the leaderboards will be shown.

ShowLeaderboardUI ( string leaderboardId ) : void

Shows the standard Google Play Games leaderboard UI for the given leaderboard.

ShowLeaderboardUI ( string leaderboardId, Action callback ) : void

Shows the leaderboard UI and calls the specified callback upon completion.

ShowLeaderboardUI ( string leaderboardId, LeaderboardTimeSpan span, Action callback ) : void

Shows the leaderboard UI and calls the specified callback upon completion.

SignOut ( ) : void

Sign out. After signing out, Authenticate must be called again to sign back in.

UnlockAchievement ( string achievementID, Action callback ) : void

Unlocks the achievement with the passed identifier. This is a Play Games extension of the ISocialPlatform API.

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.

Private Methods

Method Description
GetFriends ( ) : IUserProfile[]

Internal implmentation of getFriends.Gets the friends.

HandleLoadingScores ( GooglePlayGames.PlayGamesLeaderboard board, GooglePlayGames.BasicApi.LeaderboardScoreData scoreData, Action callback ) : void

Handles the processing of scores during loading.

MapId ( string id ) : string

Maps the alias to the identifier.

This maps an aliased ID to the actual id. The intent of this method is to allow easy to read constants to be used instead of the generated ids.

PlayGamesPlatform ( IPlayGamesClient client ) : System

Initializes a new instance of the GooglePlayGames.PlayGamesPlatform class.

PlayGamesPlatform ( GooglePlayGames.BasicApi.PlayGamesClientConfiguration configuration ) : System

Initializes a new instance of the GooglePlayGames.PlayGamesPlatform class.

Method Details

Activate() public static method

Activates the Play Games platform as the implementation of Social.Active. After calling this method, you can call methods on Social.Active. For example, Social.Active.Authenticate().
public static Activate ( ) : PlayGamesPlatform
return PlayGamesPlatform

AddIdMapping() public method

Specifies that the ID fromId should be implicitly replaced by toId on any calls that take a leaderboard or achievement ID.
After a mapping is registered, you can use fromId instead of toId when making a call. For example, the following two snippets are equivalent: ReportProgress("Cfiwjew894_AQ", 100.0, callback); ...is equivalent to: AddIdMapping("super-combo", "Cfiwjew894_AQ"); ReportProgress("super-combo", 100.0, callback);
public AddIdMapping ( string fromId, string toId ) : void
fromId string /// The identifier to map. ///
toId string /// The identifier that fromId will be mapped to. ///
return void

Authenticate() public method

Authenticate the local user with the Google Play Games service.
public Authenticate ( string>.Action callback ) : void
callback string>.Action /// The callback to call when authentication finishes. It will be called /// with true if authentication was successful, false /// otherwise. ///
return void

Authenticate() public method

Authenticate the local user with the Google Play Games service.
public Authenticate ( string>.Action callback, bool silent ) : void
callback string>.Action /// The callback to call when authentication finishes. It will be called /// with true if authentication was successful, false /// otherwise. ///
silent bool /// Indicates whether authentication should be silent. If false, /// authentication may show popups and interact with the user to obtain /// authorization. If true, there will be no popups or interaction with /// the user, and the authentication will fail instead if such interaction /// is required. A typical pattern is to try silent authentication on startup /// and, if that fails, present the user with a "Sign in" button that then /// triggers normal (not silent) authentication. ///
return void

Authenticate() public method

Authenticate the local user with the Google Play Games service.
public Authenticate ( Action callback ) : void
callback Action /// The callback to call when authentication finishes. It will be called /// with true if authentication was successful, false /// otherwise. ///
return void

Authenticate() public method

Authenticate the local user with the Google Play Games service.
public Authenticate ( Action callback, bool silent ) : void
callback Action /// The callback to call when authentication finishes. It will be called /// with true if authentication was successful, false /// otherwise. ///
silent bool /// Indicates whether authentication should be silent. If false, /// authentication may show popups and interact with the user to obtain /// authorization. If true, there will be no popups or interaction with /// the user, and the authentication will fail instead if such interaction /// is required. A typical pattern is to try silent authentication on startup /// and, if that fails, present the user with a "Sign in" button that then /// triggers normal (not silent) authentication. ///
return void

Authenticate() public method

Provided for compatibility with ISocialPlatform.
public Authenticate ( ILocalUser unused, string>.Action callback ) : void
unused ILocalUser Unused parameter for this implementation.
callback string>.Action Callback invoked when complete.
return void

Authenticate() public method

Provided for compatibility with ISocialPlatform.
public Authenticate ( ILocalUser unused, Action callback ) : void
unused ILocalUser Unused parameter for this implementation.
callback Action Callback invoked when complete.
return void

CreateAchievement() public method

Creates an achievement object which may be subsequently used to report an achievement.
public CreateAchievement ( ) : IAchievement
return IAchievement

CreateLeaderboard() public method

Returns a leaderboard object that can be configured to load scores.
public CreateLeaderboard ( ) : ILeaderboard
return ILeaderboard

GetAccessToken() public method

Returns an id token for the user.
public GetAccessToken ( ) : string
return string

GetAchievement() public method

Returns the achievement corresponding to the passed achievement identifier.
public GetAchievement ( string achievementId ) : GooglePlayGames.BasicApi.Achievement
achievementId string /// The identifier of the achievement. ///
return GooglePlayGames.BasicApi.Achievement

GetApiClient() public method

Gets pointer to the Google API client.
This is provided as a helper to making additional JNI calls. This connection is initialized and controlled by the underlying SDK.
public GetApiClient ( ) : IntPtr
return System.IntPtr

GetIdToken() public method

Get an id token for the user.
public GetIdToken ( Action idTokenCallback ) : void
idTokenCallback Action A callback to be invoked after token is retrieved. Will be passed null value /// on failure.
return void

GetLoading() public method

Check if the leaderboard is currently loading.
public GetLoading ( ILeaderboard board ) : bool
board ILeaderboard The leaderboard to check for loading in progress
return bool

GetPlayerStats() public method

Gets the player stats.
public GetPlayerStats ( PlayerStats>.Action callback ) : void
callback PlayerStats>.Action Callback invoked when completed.
return void

GetServerAuthCode() public method

Gets the server auth code.
This code is used by the server application in order to get an oauth token. For how to use this acccess token please see: https://developers.google.com/drive/v2/web/auth/web-server
public GetServerAuthCode ( string>.Action callback ) : void
callback string>.Action Callback.
return void

GetToken() public method

Retrieves a bearer token associated with the current account.
public GetToken ( ) : string
return string

GetUserDisplayName() public method

Returns the user's display name.
public GetUserDisplayName ( ) : string
return string

GetUserEmail() public method

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.
public GetUserEmail ( ) : string
return string

GetUserEmail() public method

Gets the user's email with a callback.
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.
public GetUserEmail ( string>.Action callback ) : void
callback string>.Action The callback with a status code of the request, /// and string which is the email. It can be null.
return void

GetUserId() public method

Returns the user's Google ID.
public GetUserId ( ) : string
return string

GetUserImageUrl() public method

Returns the user's avatar URL if they have one.
public GetUserImageUrl ( ) : string
return string

IncrementAchievement() public method

Increments an achievement. This is a Play Games extension of the ISocialPlatform API.
public IncrementAchievement ( string achievementID, int steps, Action callback ) : void
achievementID string /// The ID of the achievement to increment. This can be a raw Google Play /// Games achievement ID (alphanumeric string), or an alias that was previously configured /// by a call to . ///
steps int /// The number of steps to increment the achievement by. ///
callback Action /// The callback to call to report the success or failure of the operation. The callback /// will be called with true to indicate success or false for failure. ///
return void

InitializeInstance() public static method

Initializes the instance of Play Game Services platform.
This creates the singleton instance of the platform. Multiple calls to this method are ignored.
public static InitializeInstance ( GooglePlayGames.BasicApi.PlayGamesClientConfiguration configuration ) : void
configuration GooglePlayGames.BasicApi.PlayGamesClientConfiguration Configuration to use when initializing.
return void

InitializeNearby() public static method

Initializes the nearby connection platform.
This call initializes the nearby connection platform. This is independent of the Play Game Services initialization. Multiple calls to this method are ignored.
public static InitializeNearby ( Action callback ) : void
callback Action Callback invoked when complete.
return void

IsAuthenticated() public method

Determines whether the user is authenticated.
public IsAuthenticated ( ) : bool
return bool

LoadAchievementDescriptions() public method

Loads the Achievement descriptions.
public LoadAchievementDescriptions ( Action callback ) : void
callback Action The callback to receive the descriptions
return void

LoadAchievements() public method

Loads the achievement state for the current user.
public LoadAchievements ( Action callback ) : void
callback Action The callback to receive the achievements
return void

LoadFriends() public method

Loads the friends that also play this game. See loadConnectedPlayers.
This is a callback variant of LoadFriends. When completed, the friends list set in the user object, so they can accessed via the friends property as needed.
public LoadFriends ( ILocalUser user, Action callback ) : void
user ILocalUser The current local user
callback Action Callback invoked when complete.
return void

LoadMoreScores() public method

Loads more scores.
This is used to load the next "page" of scores.
public LoadMoreScores ( GooglePlayGames.BasicApi.ScorePageToken token, int rowCount, Action callback ) : void
token GooglePlayGames.BasicApi.ScorePageToken Token used to recording the loading.
rowCount int Row count.
callback Action Callback invoked when complete.
return void

LoadScores() public method

Loads the leaderboard based on the constraints in the leaderboard object.
public LoadScores ( ILeaderboard board, Action callback ) : void
board ILeaderboard The leaderboard object. This is created by /// calling CreateLeaderboard(), and then initialized appropriately.
callback Action Callback invoked when complete.
return void

LoadScores() public method

Loads the scores relative the player.
This returns the 25 (which is the max results returned by the SDK per call) scores that are around the player's score on the Public, all time leaderboard. Use the overloaded methods which are specific to GPGS to modify these parameters.
public LoadScores ( string leaderboardId, Action callback ) : void
leaderboardId string Leaderboard Id
callback Action Callback to invoke when completed.
return void

LoadScores() public method

Loads the scores using the provided parameters.
public LoadScores ( string leaderboardId, LeaderboardStart start, int rowCount, LeaderboardCollection collection, LeaderboardTimeSpan timeSpan, Action callback ) : void
leaderboardId string Leaderboard identifier.
start LeaderboardStart Start either top scores, or player centered.
rowCount int Row count. the number of rows to return.
collection LeaderboardCollection Collection. social or public
timeSpan LeaderboardTimeSpan Time span. daily, weekly, all-time
callback Action Callback to invoke when completed.
return void

LoadUsers() public method

Loads the users.
public LoadUsers ( string userIds, Action callback ) : void
userIds string User identifiers.
callback Action Callback invoked when complete.
return void

RegisterInvitationDelegate() public method

Register an invitation delegate to be notified when a multiplayer invitation arrives
public RegisterInvitationDelegate ( InvitationReceivedDelegate deleg ) : void
deleg InvitationReceivedDelegate The delegate to register
return void

ReportProgress() public method

Reports the progress of an achievement (reveal, unlock or increment). This method attempts to implement the expected behavior of ISocialPlatform.ReportProgress as closely as possible, as described below. Although this method works with incremental achievements for compatibility purposes, calling this method for incremental achievements is not recommended, since the Play Games API exposes incremental achievements in a very different way than the interface presented by ISocialPlatform.ReportProgress. The implementation of this method for incremental achievements attempts to produce the correct result, but may be imprecise. If possible, call IncrementAchievement instead.
public ReportProgress ( string achievementID, double progress, Action callback ) : void
achievementID string /// The ID of the achievement to unlock, reveal or increment. This can be a raw Google Play /// Games achievement ID (alphanumeric string), or an alias that was previously configured /// by a call to . ///
progress double /// Progress of the achievement. If the achievement is standard (not incremental), then /// a progress of 0.0 will reveal the achievement and 100.0 will unlock it. Behavior of other /// values is undefined. If the achievement is incremental, then this value is interpreted /// as the total percentage of the achievement's progress that the player should have /// as a result of this call (regardless of the progress they had before). So if the /// player's previous progress was 30% and this call specifies 50.0, the new progress will /// be 50% (not 80%). ///
callback Action /// Callback that will be called to report the result of the operation: true on /// success, false otherwise. ///
return void

ReportScore() public method

Reports a score to a leaderboard.
public ReportScore ( long score, string board, Action callback ) : void
score long /// The score to report. ///
board string /// The ID of the leaderboard on which the score is to be posted. This may be a raw /// Google Play Games leaderboard ID or an alias configured through a call to /// . ///
callback Action /// The callback to call to report the success or failure of the operation. The callback /// will be called with true to indicate success or false for failure. ///
return void

ReportScore() public method

Submits the score for the currently signed-in player to the leaderboard associated with a specific id and metadata (such as something the player did to earn the score).
public ReportScore ( long score, string board, string metadata, Action callback ) : void
score long Score to report.
board string leaderboard id.
metadata string metadata about the score.
callback Action Callback invoked upon completion.
return void

SetDefaultLeaderboardForUI() public method

Sets the default leaderboard for the leaderboard UI. After calling this method, a call to ShowLeaderboardUI will show only the specified leaderboard instead of showing the list of all leaderboards.
public SetDefaultLeaderboardForUI ( string lbid ) : void
lbid string /// The ID of the leaderboard to display on the default UI. This may be a raw /// Google Play Games leaderboard ID or an alias configured through a call to /// . ///
return void

SetStepsAtLeast() public method

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.
public SetStepsAtLeast ( string achievementID, int steps, Action callback ) : void
achievementID string /// The ID of the achievement to increment. This can be a raw Google Play /// Games achievement ID (alphanumeric string), or an alias that was previously configured /// by a call to . ///
steps int /// The number of steps to increment the achievement by. ///
callback Action /// The callback to call to report the success or failure of the operation. The callback /// will be called with true to indicate success or false for failure. ///
return void

ShowAchievementsUI() public method

Shows the standard Google Play Games achievements user interface, which allows the player to browse their achievements.
public ShowAchievementsUI ( ) : void
return void

ShowAchievementsUI() public method

Shows the standard Google Play Games achievements user interface, which allows the player to browse their achievements.
public ShowAchievementsUI ( Action callback ) : void
callback Action If non-null, the callback is invoked when /// the achievement UI is dismissed
return void

ShowLeaderboardUI() public method

Shows the standard Google Play Games leaderboards user interface, which allows the player to browse their leaderboards. If you have configured a specific leaderboard as the default through a call to SetDefaultLeaderboardForUi, the UI will show that specific leaderboard only. Otherwise, a list of all the leaderboards will be shown.
public ShowLeaderboardUI ( ) : void
return void

ShowLeaderboardUI() public method

Shows the standard Google Play Games leaderboard UI for the given leaderboard.
public ShowLeaderboardUI ( string leaderboardId ) : void
leaderboardId string /// The ID of the leaderboard to display. This may be a raw /// Google Play Games leaderboard ID or an alias configured through a call to /// . ///
return void

ShowLeaderboardUI() public method

Shows the leaderboard UI and calls the specified callback upon completion.
public ShowLeaderboardUI ( string leaderboardId, Action callback ) : void
leaderboardId string leaderboard ID, can be null meaning all leaderboards.
callback Action Callback to call. If null, nothing is called.
return void

ShowLeaderboardUI() public method

Shows the leaderboard UI and calls the specified callback upon completion.
public ShowLeaderboardUI ( string leaderboardId, LeaderboardTimeSpan span, Action callback ) : void
leaderboardId string leaderboard ID, can be null meaning all leaderboards.
span LeaderboardTimeSpan Timespan to display scores in the leaderboard.
callback Action Callback to call. If null, nothing is called.
return void

SignOut() public method

Sign out. After signing out, Authenticate must be called again to sign back in.
public SignOut ( ) : void
return void

UnlockAchievement() public method

Unlocks the achievement with the passed identifier. This is a Play Games extension of the ISocialPlatform API.
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.
public UnlockAchievement ( string achievementID, Action callback ) : void
achievementID string /// The ID of the achievement to increment. This can be a raw Google Play /// Games achievement ID (alphanumeric string), or an alias that was previously configured /// by a call to . ///
callback Action /// The callback to call to report the success or failure of the operation. The callback /// will be called with true to indicate success or false for failure. ///
return void