Class SavegameManager
Abstract base class for all savegame manager implementations.
There can be many, such as XML based ones, others that use JSON, or even ProtoBuf, YAML, msgpack, well... the possibilities are endless.
They all share the same raw and basic functionalities defined in here though.
Namespace: GlitchedPolygons.SavegameFramework
Assembly: UnityScriptsLibrary.dll
Syntax
public abstract class SavegameManager : MonoBehaviour
Fields
| Improve this Doc View SourcebatchSize
How many objects should be batched during saving / loading per frame.
Declaration
protected int batchSize
Field Value
| Type | Description |
|---|---|
| System.Int32 |
Remarks
E.g. a value of 256 in a big scene would spread the serialization of all the objects over multiple frames: every 256 processed objects,
yield return YieldInstructions.WaitForEndOfFrame; is called! Put a lot of thought into what value to use here,
because you don't want to brick the game during saving but also not spread the saving procedure over multiple seconds, causing state inconsistencies!
collectGarbageOnLoad
System.GC.Collect after loading a savegame?
Declaration
protected bool collectGarbageOnLoad
Field Value
| Type | Description |
|---|---|
| System.Boolean |
collectGarbageOnSave
Collect generated garbage after saving?
Declaration
protected bool collectGarbageOnSave
Field Value
| Type | Description |
|---|---|
| System.Boolean |
compress
Compress the savegame using GZip.
Declaration
protected bool compress
Field Value
| Type | Description |
|---|---|
| System.Boolean |
encrypt
Encrypt the savegame before writing it out to disk.
Declaration
protected bool encrypt
Field Value
| Type | Description |
|---|---|
| System.Boolean |
iterationsOfPBKDF2
How many rounds of PBKDF2 should be applied to key in order to derive the AES key from it?
Once decided, DO NOT CHANGE THIS value or you'll be unable to decrypt your data unless you save the used iteration count along with the data you're decrypting!
Declaration
protected int iterationsOfPBKDF2
Field Value
| Type | Description |
|---|---|
| System.Int32 |
key
Savegame encryption key.
Declaration
protected string key
Field Value
| Type | Description |
|---|---|
| System.String |
loadingTimeoutSeconds
After how many seconds of loading attempt should the procedure be aborted and considered a failure?
Declaration
protected int loadingTimeoutSeconds
Field Value
| Type | Description |
|---|---|
| System.Int32 |
savegameFileExtension
File extension to use for savegames.
Declaration
protected string savegameFileExtension
Field Value
| Type | Description |
|---|---|
| System.String |
savegamesDirectoryName
This will be the name of the folder inside Application.persistentDataPath where all savegames will be saved to and loaded from.
Declaration
protected string savegamesDirectoryName
Field Value
| Type | Description |
|---|---|
| System.String |
savegamesDirectoryPath
This is the full path to the directory that contains the savegames.
Declaration
protected string savegamesDirectoryPath
Field Value
| Type | Description |
|---|---|
| System.String |
savingTimeoutSeconds
After how many seconds of saving should the procedure be aborted and considered a failure?
Declaration
protected int savingTimeoutSeconds
Field Value
| Type | Description |
|---|---|
| System.Int32 |
TIME_FORMAT
The System.DateTime format used for the savegame timestamps.
Declaration
protected const string TIME_FORMAT = "yyyyMMddHHmmssff"
Field Value
| Type | Description |
|---|---|
| System.String |
Methods
| Improve this Doc View SourceCheckSavegamesDirectory()
Checks if the savegames directory exists and creates one if not.
Declaration
protected bool CheckSavegamesDirectory()
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the savegame directory existed; false if it had to be created. |
GetNewestSavegame()
Gets the newest, most recent savegame file name; without its extension and local to the savegamesDirectoryPath, such that it can be loaded seamlessly into a savegame manager's load function.
Declaration
protected string GetNewestSavegame()
Returns
| Type | Description |
|---|---|
| System.String |
Load(String)
Loads a savegame file from inside the savegamesDirectoryPath.
The
fileName parameter is just the savegame's file name (local to the savegamesDirectoryPath and WITHOUT THE FILE EXTENSION).This will cause a chain reaction of method calls and procedures in order to make the loading procedure and map transition as smooth as possible.
Check out the documentation of the implementing child classes to find out more about how it works (e.g. XmlSavegameManager).
Declaration
public abstract void Load(string fileName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | fileName | The savegame's file name (WITHOUT ITS EXTENSION!). Path is local to the savegamesDirectoryPath. |
See Also
| Improve this Doc View SourceLoadNewestSavegame()
Loads the most recent savegame file automatically.
Declaration
public void LoadNewestSavegame()
OnLoad()
Invokes the Loaded event.
Declaration
protected void OnLoad()
OnLoadFailed()
Invokes the LoadFailed event.
Declaration
protected void OnLoadFailed()
OnLoading()
Invokes the Loading event.
Declaration
protected void OnLoading()
OnReady()
Invokes the Ready event.
Declaration
protected void OnReady()
OnSave()
Invokes the Saved event.
Declaration
protected void OnSave()
OnSaveFailed()
Invokes the SaveFailed event.
Declaration
protected void OnSaveFailed()
OnSaving()
Invokes the Saving event.
Declaration
protected void OnSaving()
Save(String)
Saves the game out to a time-stamped savegame file inside the savegamesDirectoryPath folder.
Declaration
public abstract void Save(string fileName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | fileName | The savegame's file name (WITHOUT EXTENSION!) |
Events
| Improve this Doc View SourceLoaded
This event is raised when a savegame has been loaded (successfully!).
Declaration
public event Action Loaded
Event Type
| Type | Description |
|---|---|
| System.Action |
LoadFailed
Raised if a loading procedure failed.
Declaration
public event Action LoadFailed
Event Type
| Type | Description |
|---|---|
| System.Action |
Loading
Raised when the player initiated a load procedure (started but not yet done; use this to show some UI label like a spinning disc or something to notify the user that loading is in progress).
Declaration
public event Action Loading
Event Type
| Type | Description |
|---|---|
| System.Action |
Ready
Raised whenever the SavegameManager instance is ready again after a saving or loading procedure finished successfully.
Use this to e.g. reenable the UI buttons for saving/loading.
Declaration
public event Action Ready
Event Type
| Type | Description |
|---|---|
| System.Action |
Saved
This event is raised whenever the user saved the game (provided that the procedure was successful).
Declaration
public event Action Saved
Event Type
| Type | Description |
|---|---|
| System.Action |
SaveFailed
Raised if a saving procedure failed.
Declaration
public event Action SaveFailed
Event Type
| Type | Description |
|---|---|
| System.Action |
Saving
This event is raised whenever the user initiated a saving procedure (started but not yet done; use this to show some UI label like a spinning disc or something to notify the user that saving is in progress).
Declaration
public event Action Saving
Event Type
| Type | Description |
|---|---|
| System.Action |