GooglePlayGames. BasicApi. SavedGame. ISavedGameClient
The main entry point for interacting with saved games.
Summary
Saved games are persisted in the cloud along with several game-specific properties (ISavedGameMetadata for more information). There are several core concepts involved with saved games:
Filenames - act as unique identifiers for saved games. Two devices performing a read or write using the same filename will end up reading or modifying the same file (i.e. filenames are not device specific).
Saved Game Metadata are represented by ISavedGameMetadata. The instances allow access to metadata properties about the underlying saved game (e.g. description). In addition, metadata functions as a handle that are required to read and manipulate saved game contents. Lastly, metadata may be "Open". Open metadata instances are required to manipulate the underlying binary data of the saved game. See method comments to determine whether a specific method requires or returns an open saved game.
Conflicts occur when multiple devices attempt to write to the same file at the same time. The saved game system guarantees that no conflicting writes will be lost or silently overwritten. Instead, they must be handled the next time the file with a conflict is Opened. Conflicts can be handled automatically ( OpenWithAutomaticConflictResolution) or can be manuallyhandled by the developer (OpenWithManualConflictResolution). See the Open methods for more discussion.
Saved games will generally be used in the following workflow:
- Determine which saved game to use (either using a hardcoded filename or ShowSelectSavedGameUI)
- Open the file using OpenWithManualConflictResolution or OpenWithAutomaticConflictResolution
- Read the binary data of the saved game using ReadBinaryData handle it as appropriate for your game.
- When you have updates, persist them in the cloud using CommitUpdate. Note that writing to the cloud is relatively expensive, and shouldn't be done frequently.
See online documentation for Saved Games for more information.
Public functions |
|
---|---|
CommitUpdate(ISavedGameMetadata metadata, SavedGameMetadataUpdate updateForMetadata, byte[] updatedBinaryData, Action< SavedGameRequestStatus, ISavedGameMetadata > callback)
|
void
Durably commits an update to the passed saved game.
|
Delete(ISavedGameMetadata metadata)
|
void
Delete the specified snapshot.
|
FetchAllSavedGames(DataSource source, Action< SavedGameRequestStatus, List< ISavedGameMetadata >> callback)
|
void
Returns the metadata for all known saved games for this game.
|
OpenWithAutomaticConflictResolution(string filename, DataSource source, ConflictResolutionStrategy resolutionStrategy, Action< SavedGameRequestStatus, ISavedGameMetadata > callback)
|
void
Opens the file with the indicated name and data source.
|
OpenWithManualConflictResolution(string filename, DataSource source, bool prefetchDataOnConflict, ConflictCallback conflictCallback, Action< SavedGameRequestStatus, ISavedGameMetadata > completedCallback)
|
void
Opens the file with the indicated name and data source.
|
ReadBinaryData(ISavedGameMetadata metadata, Action< SavedGameRequestStatus, byte[]> completedCallback)
|
void
Reads the binary data of the passed saved game.
|
ShowSelectSavedGameUI(string uiTitle, uint maxDisplayedSavedGames, bool showCreateSaveUI, bool showDeleteSaveUI, Action< SelectUIStatus, ISavedGameMetadata > callback)
|
void
Shows the select saved game UI with the indicated configuration.
|
Public functions
CommitUpdate
void CommitUpdate( ISavedGameMetadata metadata, SavedGameMetadataUpdate updateForMetadata, byte[] updatedBinaryData, Action< SavedGameRequestStatus, ISavedGameMetadata > callback )
Durably commits an update to the passed saved game.
When this method returns successfully, the data is durably persisted to disk and will eventually be uploaded to the cloud (in practice, this will happen very quickly unless the device does not have a network connection). If an update to the saved game has occurred after the metadata was retrieved from the cloud, this update will produce a conflict (this commonly occurs if two different devices are writing to the cloud at the same time). All conflicts must be handled the next time this saved game is opened. See OpenWithManualConflictResolution and OpenWithAutomaticConflictResolution for more information.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
Delete
void Delete( ISavedGameMetadata metadata )
Delete the specified snapshot.
This will delete the data of the snapshot locally and on the server.
Details | |||
---|---|---|---|
Parameters |
|
FetchAllSavedGames
void FetchAllSavedGames( DataSource source, Action< SavedGameRequestStatus, List< ISavedGameMetadata >> callback )
Returns the metadata for all known saved games for this game.
All returned saved games are not open, and must be opened before they can be used for writes or binary data reads. The callback will always occur on the game thread.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
OpenWithAutomaticConflictResolution
void OpenWithAutomaticConflictResolution( string filename, DataSource source, ConflictResolutionStrategy resolutionStrategy, Action< SavedGameRequestStatus, ISavedGameMetadata > callback )
Opens the file with the indicated name and data source.
If the file has an outstanding conflict, it will be resolved using the specified conflict resolution strategy. The metadata returned by this method will be "Open" - it can be used as a parameter for CommitUpdate and ResolveConflictByChoosingMetadata.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
OpenWithManualConflictResolution
void OpenWithManualConflictResolution( string filename, DataSource source, bool prefetchDataOnConflict, ConflictCallback conflictCallback, Action< SavedGameRequestStatus, ISavedGameMetadata > completedCallback )
Opens the file with the indicated name and data source.
If there is a conflict that requires resolution, it will be resolved manually using the passed conflict callback. Once all pending conflicts are resolved, the completed callback will be invoked with the retrieved data. In the event of an error, the completed callback will be invoked with the corresponding error status. All callbacks will be executed on the game thread.
Details | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
ReadBinaryData
void ReadBinaryData( ISavedGameMetadata metadata, Action< SavedGameRequestStatus, byte[]> completedCallback )
Reads the binary data of the passed saved game.
The passed metadata must be opened (i.e. ISavedGameMetadata.IsOpen returns true). The callback will always be executed on the game thread.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
ShowSelectSavedGameUI
void ShowSelectSavedGameUI( string uiTitle, uint maxDisplayedSavedGames, bool showCreateSaveUI, bool showDeleteSaveUI, Action< SelectUIStatus, ISavedGameMetadata > callback )
Shows the select saved game UI with the indicated configuration.
If the user selects a saved game in that UI, it will be returned in the passed callback. This metadata will be unopened and must be passed to either OpenWithManualConflictResolution or OpenWithAutomaticConflictResolution in order to retrieve the binary data. The callback will always be executed on the game thread.
Details | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|