Saved Games In Unity Games - Android Developers
Maybe your like
This topics describes how to use saved games for Play Games Services in Unity games.
Before you start
Set up your project and the Google Play Games plugin for Unity. For details, see the Get started guide.
Enabled saved games. See the saved games for details.
Display the saved games UI
The standard UI for selecting or creating a saved game entry is displayed by calling:
voidShowSelectUI(){ uintmaxNumToDisplay=5; boolallowCreateNew=false; boolallowDelete=true; ISavedGameClientsavedGameClient=PlayGamesPlatform.Instance.SavedGame; savedGameClient.ShowSelectSavedGameUI("Select saved game", maxNumToDisplay, allowCreateNew, allowDelete, OnSavedGameSelected); } publicvoidOnSavedGameSelected(SelectUIStatusstatus,ISavedGameMetadatagame){ if(status==SelectUIStatus.SavedGameSelected){ // handle selected game save }else{ // handle cancel or error } }Open a saved game
In order to read or write data to a saved game, the saved game needs to be opened. Since the saved game state is cached locally on the device and saved to the cloud, it is possible to encounter conflicts in the state of the saved data. A conflict happens when a device attempts to save state to the cloud but the data currently on the cloud was written by a different device. These conflicts need to be resolved when opening the saved game data.
There are 2 open methods that handle conflict resolution, the first OpenWithAutomaticConflictResolution accepts a standard resolution strategy type and automatically resolves the conflicts. The other method, OpenWithManualConflictResolution accepts a callback method to allow the manual resolution of the conflict.
See ISavedGameClient for more details on these methods.
voidOpenSavedGame(stringfilename){ ISavedGameClientsavedGameClient=PlayGamesPlatform.Instance.SavedGame; savedGameClient.OpenWithAutomaticConflictResolution(filename,DataSource.ReadCacheOrNetwork, ConflictResolutionStrategy.UseLongestPlaytime,OnSavedGameOpened); } publicvoidOnSavedGameOpened(SavedGameRequestStatusstatus,ISavedGameMetadatagame){ if(status==SavedGameRequestStatus.Success){ // handle reading or writing of saved game. }else{ // handle error } }Write a saved game
Once the saved game file is opened, it can be written to save the game state. This is done by calling CommitUpdate. There are four parameters to CommitUpdate:
- the saved game metadata passed to the callback passed to one of the Open calls.
- the updates to make to the metadata.
- the actual byte array of data
- a callback to call when the commit is complete.
Read a saved game
Once the saved game file is opened, it can be read to load the game state. This is done by calling ReadBinaryData.
voidLoadGameData(ISavedGameMetadatagame){ ISavedGameClientsavedGameClient=PlayGamesPlatform.Instance.SavedGame; savedGameClient.ReadBinaryData(game,OnSavedGameDataRead); } publicvoidOnSavedGameDataRead(SavedGameRequestStatusstatus,byte[]data){ if(status==SavedGameRequestStatus.Success){ // handle processing the byte array data }else{ // handle error } }Delete a saved game
Once the saved game file is opened, it can be deleted. This is done by calling Delete.
voidDeleteGameData(stringfilename){ // Open the file to get the metadata. ISavedGameClientsavedGameClient=PlayGamesPlatform.Instance.SavedGame; savedGameClient.OpenWithAutomaticConflictResolution(filename,DataSource.ReadCacheOrNetwork, ConflictResolutionStrategy.UseLongestPlaytime,DeleteSavedGame); } publicvoidDeleteSavedGame(SavedGameRequestStatusstatus,ISavedGameMetadatagame){ if(status==SavedGameRequestStatus.Success){ ISavedGameClientsavedGameClient=PlayGamesPlatform.Instance.SavedGame; savedGameClient.Delete(game); }else{ // handle error } }Tag » Where Are Unity Projects Saved
-
Where Does Unity Store Project Directories? - Unity Forum
-
How To Move Or Copy A Unity Project (without Breaking It)
-
Saving Your Work - Unity - Manual
-
Saving Your Work - Unity - Manual
-
Where Are The Unity Save Files Located? : R/Unity3D - Reddit
-
Where Are Unity Projects Located
-
Manual: Saving Your Work - Unity
-
A Brief Anatomy Of A Unity Project Folder | By Jonathan Jenkins
-
Unity Erased All My Progress On My Project Back To Original State
-
Saving The Scene | Unity 2020 By Example - Third Edition
-
Breaking Down The Different Ways To Save Game Data In Unity
-
Saving Data In Unity3D Using Files - MongoDB
-
How To Save, Backup On Google Drive, And Restore Your Unity Projects
-
How To Move A Unity Project To Another Computer - Quora