Pro Reset Game
Loading...
Searching...
No Matches
SaveManager Class Reference

Manages capture, persistence, and restoration of game state for the current Unity scene. Feature overview. More...

Inheritance diagram for SaveManager:

Classes

class  SaveEntry
 Bundles a single target variable for explicit serialisation. More...
 

Public Member Functions

void RecordState ()
 Captures game state using the enabled mechanisms and immediately commits it to disk.
 
void LoadState ()
 Loads persisted state from disk and restores it into the current scene objects.
 
void Save_SaveFileToDisk (int saveSlot)
 Convenience wrapper that records state and saves it to the specified slot ID.
 
void Load_SaveFileFromDisk (int saveSlot)
 Loads a save file corresponding to saveSlot or the newest timestamped file when unlimited slots are enabled.
 
List< string > GetAllSaveFileIDs ()
 Returns all IDs currently present on disk that match SaveSlotName.
 
bool DeleteSaveFile (string id)
 Deletes a specific save file by its ID.
 
void DumpSavedDataToConsole ()
 

Public Attributes

bool SaveAllSerializableFields = false
 Toggle that determines whether SaveAllSerializableFieldsFromList/… should dump all serialisable fields from the list or hierarchy search. (All components in-scene)
 
bool SaveEverySingleComponentOrComponentInList = true
 When true, ComponentListToSaveEveryThing is used verbatim; when false, the component list is built automatically with Object.FindObjectsOfType<T>(bool). (Searching All components in-scene)
 
List< Component > ComponentListToSaveEveryThing = new List<Component>()
 Explicit set of MonoBehaviours whose fields will be saved/reloaded when SaveEverySingleComponentOrComponentInList is enabled.
 
bool IncludeBuiltinComponentProperties = true
 
bool useSaveEntries = true
 Master switch for SaveEntry-based serialisation.
 
List< SaveEntrysaveEntries = new List<SaveEntry>()
 The list of variables that will be saved and restored when useSaveEntries is true.
 
bool useSaveableAttributes = true
 Enables scanning for fields decorated with [Saveable].
 
bool SaveEverySingleAttributeComponentOrComponentInList = true
 When enabled, only the components in serializableFieldComponents are inspected for [Saveable] fields. When disabled, every MonoBehaviour in the scene is scanned.
 
List< MonoBehaviour > serializableFieldComponents = new List<MonoBehaviour>()
 Manual list of components to scan for [Saveable] fields when SaveEverySingleAttributeComponentOrComponentInList is enabled.
 
bool EnableSaveSlots = false
 Enables numeric save slots (bounded by AmountOfSaveSlots).
 
bool InfiniteSaveSlots = false
 Allows unlimited slot IDs by timestamping filenames instead of clamping to AmountOfSaveSlots.
 
int AmountOfSaveSlots = 3
 Maximum number of slots when EnableSaveSlots is true and .
 
int SlotsToSaveTo = 1
 Index used for the next save/load call when the UI selects a slot.
 
string SaveSlotName = $"Saveata_%INEX%.json"
 Filename pattern used for all save operations. The token INDEX% is replaced with a slot ID or timestamp (depending on slot mode). Checks to ensure that .json is at the end and that only one . is present in file is done. Warning in editor or console error at awake.
 
bool EnableFileEncryption = true
 Enables AES-256-CBC encryption during disk IO.
 
string encryptionPassword = ""
 48-character password; the first 32 chars form the AES key, the last 16 form the IV. Required 48 characters, nothing shorter or longer
 

Detailed Description

Manages capture, persistence, and restoration of game state for the current Unity scene. Feature overview.

Explicit entries – Save/restore individual variables declared in inspector.

[Saveable] attribute – Automatically pick up fields marked with [Saveable] Example: [Saveable] public int health = 100;

Serializable field dump – Persist every Unity-serialisable field on either all elements or subsection provided in inspector.

Save-slot system – Fixed or unlimited slot counts, with optional AES-256 encryption.

Typical workflow

Configure serialisation options in the inspector (or via script). Call to capture state and write it to disk. Call – or the slot-aware variants – to restore state at a later time.

All data are stored in Application.persistentDataPath. When encryption is enabled, files are written as plaintext first and then overwritten with the ciphertext.

Member Function Documentation

◆ DeleteSaveFile()

bool SaveManager.DeleteSaveFile ( string id)

Deletes a specific save file by its ID.

Parameters
idSlot index or timestamp string to remove.
Returns
true when the file existed and was deleted.

◆ DumpSavedDataToConsole()

void SaveManager.DumpSavedDataToConsole ( )

Writes the current savedData contents to the Unity Console in a human-readable, column-aligned format.
Call this after RecordState() or LoadState() to inspect what was captured / restored.

◆ GetAllSaveFileIDs()

List< string > SaveManager.GetAllSaveFileIDs ( )

Returns all IDs currently present on disk that match SaveSlotName.

Returns
List of slot indices or timestamp strings (depending on slot mode).

◆ Load_SaveFileFromDisk()

void SaveManager.Load_SaveFileFromDisk ( int saveSlot)

Loads a save file corresponding to saveSlot or the newest timestamped file when unlimited slots are enabled.

Parameters
saveSlotSlot index to load.

◆ LoadState()

void SaveManager.LoadState ( )

Loads persisted state from disk and restores it into the current scene objects.

◆ RecordState()

void SaveManager.RecordState ( )

Captures game state using the enabled mechanisms and immediately commits it to disk.

◆ Save_SaveFileToDisk()

void SaveManager.Save_SaveFileToDisk ( int saveSlot)

Convenience wrapper that records state and saves it to the specified slot ID.

Parameters
saveSlotSlot index to overwrite when EnableSaveSlots is enabled. Ignored when slots are unlimited (timestamp mode).

Member Data Documentation

◆ AmountOfSaveSlots

int SaveManager.AmountOfSaveSlots = 3

Maximum number of slots when EnableSaveSlots is true and .

◆ ComponentListToSaveEveryThing

List<Component> SaveManager.ComponentListToSaveEveryThing = new List<Component>()

Explicit set of MonoBehaviours whose fields will be saved/reloaded when SaveEverySingleComponentOrComponentInList is enabled.

◆ EnableFileEncryption

bool SaveManager.EnableFileEncryption = true

Enables AES-256-CBC encryption during disk IO.

◆ EnableSaveSlots

bool SaveManager.EnableSaveSlots = false

Enables numeric save slots (bounded by AmountOfSaveSlots).

◆ encryptionPassword

string SaveManager.encryptionPassword = ""

48-character password; the first 32 chars form the AES key, the last 16 form the IV. Required 48 characters, nothing shorter or longer

◆ IncludeBuiltinComponentProperties

bool SaveManager.IncludeBuiltinComponentProperties = true

◆ InfiniteSaveSlots

bool SaveManager.InfiniteSaveSlots = false

Allows unlimited slot IDs by timestamping filenames instead of clamping to AmountOfSaveSlots.

◆ SaveAllSerializableFields

bool SaveManager.SaveAllSerializableFields = false

Toggle that determines whether SaveAllSerializableFieldsFromList/… should dump all serialisable fields from the list or hierarchy search. (All components in-scene)

◆ saveEntries

List<SaveEntry> SaveManager.saveEntries = new List<SaveEntry>()

The list of variables that will be saved and restored when useSaveEntries is true.

◆ SaveEverySingleAttributeComponentOrComponentInList

bool SaveManager.SaveEverySingleAttributeComponentOrComponentInList = true

When enabled, only the components in serializableFieldComponents are inspected for [Saveable] fields. When disabled, every MonoBehaviour in the scene is scanned.

◆ SaveEverySingleComponentOrComponentInList

bool SaveManager.SaveEverySingleComponentOrComponentInList = true

When true, ComponentListToSaveEveryThing is used verbatim; when false, the component list is built automatically with Object.FindObjectsOfType<T>(bool). (Searching All components in-scene)

◆ SaveSlotName

string SaveManager.SaveSlotName = $"Saveata_%INEX%.json"

Filename pattern used for all save operations. The token INDEX% is replaced with a slot ID or timestamp (depending on slot mode). Checks to ensure that .json is at the end and that only one . is present in file is done. Warning in editor or console error at awake.

◆ serializableFieldComponents

List<MonoBehaviour> SaveManager.serializableFieldComponents = new List<MonoBehaviour>()

Manual list of components to scan for [Saveable] fields when SaveEverySingleAttributeComponentOrComponentInList is enabled.

◆ SlotsToSaveTo

int SaveManager.SlotsToSaveTo = 1

Index used for the next save/load call when the UI selects a slot.

◆ useSaveableAttributes

bool SaveManager.useSaveableAttributes = true

Enables scanning for fields decorated with [Saveable].

◆ useSaveEntries

bool SaveManager.useSaveEntries = true

Master switch for SaveEntry-based serialisation.


The documentation for this class was generated from the following file: