本文档定义了游戏数据的存储结构、序列化方式及云存档策略。
我们将数据分为两类,分开存储:
user.dat).slot_0.save).不使用 Unity 自带的 PlayerPrefs 或 JsonUtility (性能差且不支持复杂结构)。
Newtonsoft.Json (开发期方便调试) 或 MessagePack / Protobuf (发布期高性能)。ISaveable 接口。public interface ISaveable {
object CaptureState();
void RestoreState(object state);
}
{
"version": "1.0.2",
"timestamp": 1701234567,
"player": {
"stats": {"hp": 100, "gold": 500},
"inventory": [...]
},
"world": {
"wave_index": 5,
"towers": [
{"id": "T01", "pos": {"x":10, "y":5}, "tier": 2}
]
}
}
虽然是单机为主,但为了维护排行榜公正性:
int, 而是存 XorInt 结构,防止 Cheat Engine 简单搜索。version 字段。MigrationService 进行数据补全或转换。