游戏存档
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助游戏存档服务,您可以轻松将玩家的游戏进度保存到 Google 的服务器。游戏可以检索游戏存档数据,以便回访玩家在任意设备上从上一个存档点继续玩游戏。
游戏存档服务可在多个设备之间同步玩家的游戏数据。例如,如果您开发了一款在 Android 上运行的游戏,则可以使用游戏存档服务,让玩家在 Android 手机上启动游戏,然后在平板电脑上继续玩游戏,而不会丢失任何进度。此外,此服务可用于确保玩家从上次停下的地方继续游戏,即使设备丢失、销毁或通过以旧换新更换为新型号也是如此。
如需了解如何为您的平台实现游戏存档,请参阅客户端实现。
游戏存档基础知识
游戏存档由以下两部分组成:
- 非结构化二进制 blob - 这些数据可表示您选择的任何内容,游戏负责解析和写入这些数据。
- 结构化元数据 - 与二进制数据相关联的其他属性,可允许 Google Play 游戏服务在默认游戏存档列表界面 (UI) 中直观呈现游戏存档,并在 Google Play 游戏应用中显示实用信息(例如上次更新时间戳)。
游戏可为单人写入任意数量的游戏存档,但受用户配额限制,因此不会强制限制玩家只能保存一个存档文件。
封面图片
除了永久性功能之外,游戏存档服务还提供视觉用户体验。我们强烈建议您将代表性图片与相应存档文件相关联。如果您在游戏中使用 Play 游戏 SDK 提供的默认游戏存档列表界面 (UI),该界面将显示这些封面图片。封面图片还会显示在 Google Play 游戏应用中。
说明
您可以为特定游戏存档内容提供简短文字说明。此说明直接面向玩家展示,应总结游戏存档代表的状态;例如,“与黑暗森林中的地精战斗”。
配额
开发者无需为存储在云端的任何游戏存档数据付费。这些数据会计入玩家的 Google 云端硬盘配额,您完全不必担心。游戏开发者只需要关注他们的 Google Drive API 配额。
读取/写入隔离
所有游戏存档都存储在玩家的 Google 云端硬盘“应用数据”文件夹中。此文件夹只能由您的游戏读取和写入,其他开发者的游戏无法查看和修改此文件夹,因此可以提供额外的保护,防止数据损坏。此外,玩家无法直接改动游戏存档,因此他们无法修改单个游戏存档。
离线支持
在玩家的设备离线时,您的游戏仍可读取和写入游戏存档,但在设备建立网络连接前无法与 Google Play 游戏服务同步。重新联网后,Google Play 游戏服务会异步更新 Google 服务器上的游戏存档数据。
冲突解决
使用游戏存档服务时,您的游戏可能会在尝试保存数据时遇到冲突。当用户在不同设备或计算机上运行应用的多个实例时,可能会发生一些冲突。您的应用必须能够解决这些冲突,同时提供最佳用户体验。
通常,如果应用实例在尝试加载或保存数据时无法访问游戏存档服务,将会发生数据冲突。一般而言,避免数据冲突的最佳方式是在应用启动或恢复时始终从游戏存档服务加载最新数据,并按照合理的频率将数据保存到该服务。不过,有时无法避免数据冲突。您的应用应尽可能处理冲突,以便保留用户的数据,并为他们提供良好的体验。
限制
目前,Google Play 游戏服务对二进制数据和封面图片强制执行的大小上限分别为 3 MB 和 800 KB。
游戏存档的结构化元数据包含以下属性:
属性 |
说明 |
ID |
Google Play 游戏服务为相应游戏存档生成的唯一字符串。可以使用此 ID 引用游戏客户端中的游戏存档。 |
Name |
开发者提供的游戏存档简称,例如“Save slot 1”或“PlayerName_Save1”。玩家不会看到此简称。 |
Description |
开发者提供的游戏存档说明。 |
Last modified |
Google Play 游戏服务针对游戏存档上次更新时间生成的时间戳(以毫秒为单位)。 |
Played time |
开发者提供的时间(以毫秒为单位),显示在游戏存档中。此值应表示玩家玩相应已存档游戏的时长。例如,Google Play 游戏服务会将已玩时间值 3600000 显示为“1 小时”。 |
Cover image |
此属性是可选属性,由开发者提供,包含封面图片的相关信息。 |
客户端实现
如需了解如何为您的平台实现游戏存档,请参阅以下资源:
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[],[],null,["# Saved games\n\nThe Saved Games service gives you a convenient way to save\nyour players' game progression to Google's servers. Your game can retrieve the\nsaved game data to allow returning players to continue a game at their last\nsave point from any device. \n\nThe Saved Games service makes it possible to synchronize a player's game data\nacross multiple devices. For example, if you have a game that\nruns on Android, you can use the Saved Games service to\nallow a player to start a game on their Android phone, and then\ncontinue playing on a tablet without losing any of their progress. This service\ncan also be used to ensure that a player's game play\ncontinues from where it left off even if their device is lost, destroyed, or\ntraded in for a newer model.\n| **Note:** Before using the Saved Games service, you must first [enable it in Google Play Console](/games/pgs/console/enable-features#enabling_saved_games).\n\nTo learn how to implement saved games for your platform, see\n[Client implementations](#client_implementations).\n\nSaved Games basics\n------------------\n\nA saved game consists of two parts:\n\n- An unstructured binary blob - this data can represent whatever you choose, and your game is responsible for parsing and writing to it.\n- Structured metadata - additional [properties](#saved_game_metadata) associated with the binary data that allow Google Play Games Services to visually present Saved Games in the default Saved Games list user interface (UI), and to present useful information in the [Google Play Games app](//play.google.com/store/apps/details?id=com.google.android.play.games) (for example, last updated timestamp).\n\nA game can write an arbitrary number of Saved Games for a single player,\nsubject to [user quota](#quota), so there is no hard requirement to restrict\nplayers to a single save file.\n\n### Cover images\n\nThe Saved Games service provides a visual user experience in addition to\npersistence features. You are strongly encouraged to associate representative\nimages with corresponding save files. If you are using the default Saved Games\nlist user interface (UI) provided by the Play Games SDK in your game,\nthe UI will display these cover images. The cover images may also appear in the\n[Google Play Games app](//play.google.com/store/apps/details?id=com.google.android.play.games).\n\n### Descriptions\n\nYou can provide a short text description of the content of a particular saved\ngame. This description is directly displayed to players and should summarize\nthe state that the saved game represents; for example, \"Fighting the Goblins\nin the Dark Woods\".\n\n### Quota\n\nDevelopers are not charged for any saved game data that's stored in the cloud.\nInstead, this data is counted against the player's Google Drive quota - you\nnever have to worry about it. The only quota that game developers need to care\nabout is their Google Drive API quota.\n\n### Read/Write isolation\n\nAll Saved Games are stored in your players' Google Drive Application Data\nFolder. This folder can only be read and written by your game - it cannot be\nviewed or modified by other developers' games, so there is additional protection\nagainst data corruption. In addition, Saved Games are insulated from direct\ntampering by players so they cannot modify individual Saved Games.\n\n### Offline support\n\nYour game can still read and write to a saved game when the player's device is\noffline, but will not be able to sync with Google Play Games Services until\nnetwork connectivity is established. Once reconnected, Google Play Games Services\nasynchronously updates the saved game data on Google's servers.\n\n### Conflict resolution\n\nWhen using the Saved Games service, your game may encounter conflicts when\nattempting to save data. These conflicts can occur when a user is running more\nthan one instance of your application on different devices or computers. Your\napplication must be able to resolve these conflicts in a way that provides the\nbest user experience.\n\nTypically, data conflicts occur when an instance of your application is unable\nto reach the Saved Games service while attempting to load data or save it. In\ngeneral, the best way to avoid data conflicts is to always load the latest data\nfrom the service when your application starts up or resumes, and save data to\nthe service with reasonable frequency. However, it is not always possible to\navoid data conflicts. Your application should make every effort to handle\nconflicts such that your users' data is preserved and that they have a good\nexperience.\n\n### Limits\n\nGoogle Play Games Services currently enforce size limits on binary data and cover\nimage sizes of 3 MB and 800 KB respectively.\n\n### Saved game metadata\n\nThe structured metadata for a saved game contains these these properties:\n\n| Property | Description |\n|-------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **ID** | A unique string generated by Google Play Games Services for this saved game. Use this ID to refer to the saved game in your game clients. |\n| **Name** | A developer-supplied short name for the saved game, for example \"Save slot 1\" or \"PlayerName_Save1\". This is not shown to players. |\n| **Description** | A developer-supplied description of the saved game. |\n| **Last modified** | Timestamp in milliseconds generated by Google Play Games Services for when the saved game was last updated. |\n| **Played time** | A developer-supplied time (in milliseconds) to display on the saved game. This value should represent how long the player has played the corresponding save game. For example, a played time value of 3600000 will be displayed by Google Play Games Services as \"1 hr\". |\n| **Cover image** | This is an optional, developer-supplied property that contains information about the [cover image](/games/pgs/savedgames#cover_images). |\n\nClient implementations\n----------------------\n\nTo learn how to implement Saved Games for your platform, see the following\nresources:\n\n- [Android](/games/pgs/android/saved-games)\n- [Checklist for implementing saved games](/games/pgs/quality#saved-games)"]]