Show / Hide Table of Contents

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.

Inheritance
System.Object
SavegameManager
JsonSavegameManager
XmlSavegameManager
Namespace: GlitchedPolygons.SavegameFramework
Assembly: UnityScriptsLibrary.dll
Syntax
public abstract class SavegameManager : MonoBehaviour

Fields

| Improve this Doc View Source

batchSize

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!

| Improve this Doc View Source

collectGarbageOnLoad

System.GC.Collect after loading a savegame?

Declaration
protected bool collectGarbageOnLoad
Field Value
Type Description
System.Boolean
| Improve this Doc View Source

collectGarbageOnSave

Collect generated garbage after saving?

Declaration
protected bool collectGarbageOnSave
Field Value
Type Description
System.Boolean
| Improve this Doc View Source

compress

Compress the savegame using GZip.

Declaration
protected bool compress
Field Value
Type Description
System.Boolean
| Improve this Doc View Source

encrypt

Encrypt the savegame before writing it out to disk.

Declaration
protected bool encrypt
Field Value
Type Description
System.Boolean
| Improve this Doc View Source

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
| Improve this Doc View Source

key

Savegame encryption key.

Declaration
protected string key
Field Value
Type Description
System.String
| Improve this Doc View Source

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
| Improve this Doc View Source

savegameFileExtension

File extension to use for savegames.

Declaration
protected string savegameFileExtension
Field Value
Type Description
System.String
| Improve this Doc View Source

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
| Improve this Doc View Source

savegamesDirectoryPath

This is the full path to the directory that contains the savegames.

Declaration
protected string savegamesDirectoryPath
Field Value
Type Description
System.String
| Improve this Doc View Source

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
| Improve this Doc View Source

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 Source

CheckSavegamesDirectory()

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.

| Improve this Doc View Source

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
| Improve this Doc View Source

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
XmlSavegameManager
JsonSavegameManager
| Improve this Doc View Source

LoadNewestSavegame()

Loads the most recent savegame file automatically.

Declaration
public void LoadNewestSavegame()
| Improve this Doc View Source

OnLoad()

Invokes the Loaded event.

Declaration
protected void OnLoad()
| Improve this Doc View Source

OnLoadFailed()

Invokes the LoadFailed event.

Declaration
protected void OnLoadFailed()
| Improve this Doc View Source

OnLoading()

Invokes the Loading event.

Declaration
protected void OnLoading()
| Improve this Doc View Source

OnReady()

Invokes the Ready event.

Declaration
protected void OnReady()
| Improve this Doc View Source

OnSave()

Invokes the Saved event.

Declaration
protected void OnSave()
| Improve this Doc View Source

OnSaveFailed()

Invokes the SaveFailed event.

Declaration
protected void OnSaveFailed()
| Improve this Doc View Source

OnSaving()

Invokes the Saving event.

Declaration
protected void OnSaving()
| Improve this Doc View Source

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 Source

Loaded

This event is raised when a savegame has been loaded (successfully!).

Declaration
public event Action Loaded
Event Type
Type Description
System.Action
| Improve this Doc View Source

LoadFailed

Raised if a loading procedure failed.

Declaration
public event Action LoadFailed
Event Type
Type Description
System.Action
| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

SaveFailed

Raised if a saving procedure failed.

Declaration
public event Action SaveFailed
Event Type
Type Description
System.Action
| Improve this Doc View Source

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
  • Improve this Doc
  • View Source
Back to top Generated by DocFX