Samples/ Newtonsoft JSON

This sample demonstrates a complete file-based save system using Newtonsoft JSON within Luna. It shows how to implement a concrete save manager that works seamlessly with Luna's UI components.

Refer to Save System Framework to learn about the UI-agnostic save system architecture.

What You Get

  • GameSaveManagerExample — concrete manager handling files, folders, and JSON IO
  • GameSaveDataExample — example player/save data model
  • GameSaveMetadataExample — lightweight metadata for lists and previews
  • InitializeSerializerExample — safe serializer initialization with converters and type allow-list

Quick Start

1. Initialize Serializer

Add the serializer initializer to your bootstrap scene:

CSHARP

2. Create Save Data Classes

CSHARP

3. Create Metadata Class

Define lightweight metadata for UI display:

4. Implement Save Manager

Inherit from GameSaveManager<MyGameSaveData, MyGameSaveMetadata> and implement the JSON-specific methods:

CSHARP

UI Integration

Wire your manager into Luna UI components by overriding the provider method:

CSHARP

File Locations

  • Save Directory: Application.persistentDataPath/saves/
  • File Extension: .json (configured by your manager)
  • Version: Set via GetSaveVersion() method

Advanced Features

Encryption

Add encryption/decryption in your manager's save/load methods:

Cloud Storage

Replace file IO with cloud API calls while keeping the same UI interface:

Troubleshooting

Best Practices

  • Use [JsonProperty(Order = -100)] on Metadata for fast metadata reads
  • Implement fast metadata loading to avoid deserializing full saves for UI lists
  • Keep type allow-lists minimal for security when using TypeNameHandling
  • Handle version migration in your load methods for schema changes
  • Use autosave functionality built into the manager
  • Test save/load on target platforms early in development