PixelCrushers.SaveSystem Class Reference

This is the main Save System class. More...

Inheritance diagram for PixelCrushers.SaveSystem:
Collaboration diagram for PixelCrushers.SaveSystem:

Public Member Functions

delegate string ValidateSceneNameDelegate (string sceneName, SceneValidationMode sceneValidationMode)
 
delegate void SceneLoadedDelegate (string sceneName, int sceneIndex)
 
void OnLevelWasLoaded (int level)
 
void SaveGameToSlot (int slotNumber)
 Saves a game into a slot using the storage provider on the Save System GameObject.
 
void LoadGameFromSlot (int slotNumber)
 Loads a game from a slot using the storage provider on the Save System GameObject.
 
void LoadSceneAtSpawnpoint (string sceneNameAndSpawnpoint)
 Loads a scene, optionally positioning the player at a specified spawnpoint.
 

Static Public Member Functions

static string GetCurrentSceneName ()
 
static int GetCurrentSceneIndex ()
 
static IEnumerator LoadAdditiveSceneInternal (string sceneName)
 
static void UnloadAdditiveSceneInternal (string sceneName)
 
static bool HasSavedGameInSlot (int slotNumber)
 Returns true if there is a saved game in the specified slot.
 
static void DeleteSavedGameInSlot (int slotNumber)
 Deletes the saved game in the specified slot.
 
static void SaveToSlot (int slotNumber)
 Saves the current game to a slot.
 
static void SaveToSlotImmediate (int slotNumber)
 Saves the current game to a slot synchronously and immediately.
 
static void LoadFromSlot (int slotNumber)
 Loads a game from a slot.
 
static void RegisterSaver (Saver saver)
 
static void UnregisterSaver (Saver saver)
 
static void ClearSavedGameData ()
 Clears the SaveSystem's internal saved game data cache.
 
static SavedGameData RecordSavedGameData ()
 Records the current scene's savers' data into the SaveSystem's internal saved game data cache.
 
static void UpdateSaveData (Saver saver, string data)
 Updates the SaveSystem's internal saved game data cache with data for a specific saver.
 
static void ApplySavedGameData (SavedGameData savedGameData)
 Applies the saved game data to the savers in the current scene.
 
static void ApplySavedGameData ()
 Applies the most recently recorded saved game data.
 
static void BeforeSceneChange ()
 If changing scenes manually, calls before changing scenes to inform components that listen for OnDestroy messages that they're being destroyed because of the scene change.
 
static void LoadGame (SavedGameData savedGameData)
 Loads the scene recorded in the saved game data (if saveCurrentScene is true) and applies the saved game data to it.
 
static void LoadScene (string sceneNameAndSpawnpoint)
 Loads a scene, optionally moving the player to a specified spawnpoint.
 
static void LoadAdditiveScene (string sceneName)
 Additively loads another scene.
 
static void UnloadAdditiveScene (string sceneName)
 Unloads a previously additively-loaded scene.
 
static void UnloadAllAdditiveScenes ()
 Unloads all previously additively-loaded scenes.
 
static void RestartGame (string startingSceneName)
 Clears the SaveSystem's saved game data cache and loads a starting scene.
 
static void ResetGameState ()
 Clears the SaveSystem's saved game data cache.
 
static void SaversRestartGame ()
 Calls OnRestartGame on all savers.
 
static string Serialize (object data)
 Returns a serialized version of an object using whatever serializer is assigned to the SaveSystem (JSON by default).
 
static T Deserialize< T > (string s, T data=default(T))
 Deserializes a previously-serialized string representation of an object back into an object.
 

Static Public Attributes

const int NoSceneIndex = -1
 
const string LastSavedGameSlotPlayerPrefsKey = "savedgame_lastSlotNum"
 Stores an int indicating the slot number of the most recently saved game.
 
static ValidateSceneNameDelegate validateNameScene = null
 Invoked before loading a scene by name.
 

Static Protected Member Functions

static IEnumerator DelayedSaveDataAppliedCoroutine (int frames)
 

Properties

static int version [get, set]
 Optional saved game version number of your choosing.
 
static bool saveCurrentScene [get, set]
 When loading a game, load the scene that the game was saved in.
 
static int maxSaveSlot [get, set]
 Highest save slot number allowed.
 
static int framesToWaitBeforeApplyData [get, set]
 When loading a game/scene, wait this many frames before applying saved data to allow other scripts to initialize first.
 
static int framesToWaitBeforeSaveDataAppliedEvent [get, set]
 If a saver requires additional frames after ApplyData() before the saveDataApplied() event should be called, set this property.
 
static bool debug [get, set]
 
static bool hasInstance [get]
 Checks if an instance already exists, without also implicitly creating one.
 
static SaveSystem instance [get]
 
static DataSerializer serializer [get]
 Reference to the DataSerializer in the SaveSystem's hierarchy.
 
static SavedGameDataStorer storer [get]
 Reference to the SavedGameDataStorer in the SaveSystem's hierarchy.
 
static SceneTransitionManager sceneTransitionManager [get]
 Reference to the SceneTransitionManager in the SaveSystem's hierarchy, if present.
 
bool allowNegativeSlotNumbers [get, set]
 Allow the use of negative slot numbers.
 
static List< string > addedScenes [get]
 Scenes that have been loaded additively.
 
static bool autoUnloadAdditiveScenes [get, set]
 When changing scenes, automatically unload all additively-loaded scenes.
 
static AsyncOperation currentAsyncOperation [get, set]
 Current asynchronous scene load operation, or null if none.
 
static SavedGameData currentSavedGameData [get, set]
 The saved game data recorded by the last call to SaveToSlot, LoadScene, or RecordSavedGameData.
 
static GameObject playerSpawnpoint [get, set]
 Where the player should spawn in the current scene.
 
static int currentSceneIndex [get]
 Build index of the current scene.
 

Events

static SceneLoadedDelegate sceneLoaded = delegate { }
 Invoked after a scene has been loaded.
 
static System.Action saveStarted = delegate { }
 Invoked when starting to save a game.
 
static System.Action saveEnded = delegate { }
 Invoked when finished saving a game.
 
static System.Action loadStarted = delegate { }
 Invoked when starting to load a game.
 
static System.Action loadEnded = delegate { }
 Invoked when finished loading a game.
 
static System.Action saveDataApplied = delegate { }
 Invoked after ApplyData() has been called on all savers.
 

Detailed Description

This is the main Save System class.

It runs as a singleton MonoBehaviour and provides static methods to save and load games.

Member Function Documentation

◆ ApplySavedGameData() [1/2]

static void PixelCrushers.SaveSystem.ApplySavedGameData ( )
inlinestatic

Applies the most recently recorded saved game data.

◆ ApplySavedGameData() [2/2]

static void PixelCrushers.SaveSystem.ApplySavedGameData ( SavedGameData  savedGameData)
inlinestatic

Applies the saved game data to the savers in the current scene.

Parameters
savedGameDataSaved game data.

◆ BeforeSceneChange()

static void PixelCrushers.SaveSystem.BeforeSceneChange ( )
inlinestatic

If changing scenes manually, calls before changing scenes to inform components that listen for OnDestroy messages that they're being destroyed because of the scene change.

◆ ClearSavedGameData()

static void PixelCrushers.SaveSystem.ClearSavedGameData ( )
inlinestatic

Clears the SaveSystem's internal saved game data cache.

◆ DelayedSaveDataAppliedCoroutine()

static IEnumerator PixelCrushers.SaveSystem.DelayedSaveDataAppliedCoroutine ( int  frames)
inlinestaticprotected

◆ DeleteSavedGameInSlot()

static void PixelCrushers.SaveSystem.DeleteSavedGameInSlot ( int  slotNumber)
inlinestatic

Deletes the saved game in the specified slot.

◆ Deserialize< T >()

static T PixelCrushers.SaveSystem.Deserialize< T > ( string  s,
data = default(T) 
)
inlinestatic

Deserializes a previously-serialized string representation of an object back into an object.

Uses whatever serializer is assigned to the SaveSystem (JSON by default).

Template Parameters
TThe type of the object.
Parameters
sThe object's serialized data.
dataOptional preallocated object to serialize data into.
Returns
The deserialized object, or null if it couldn't be deserialized.

◆ GetCurrentSceneIndex()

static int PixelCrushers.SaveSystem.GetCurrentSceneIndex ( )
inlinestatic

◆ GetCurrentSceneName()

static string PixelCrushers.SaveSystem.GetCurrentSceneName ( )
inlinestatic

◆ HasSavedGameInSlot()

static bool PixelCrushers.SaveSystem.HasSavedGameInSlot ( int  slotNumber)
inlinestatic

Returns true if there is a saved game in the specified slot.

◆ LoadAdditiveScene()

static void PixelCrushers.SaveSystem.LoadAdditiveScene ( string  sceneName)
inlinestatic

Additively loads another scene.

Parameters
sceneNameScene to additively load.

◆ LoadAdditiveSceneInternal()

static IEnumerator PixelCrushers.SaveSystem.LoadAdditiveSceneInternal ( string  sceneName)
inlinestatic

◆ LoadFromSlot()

static void PixelCrushers.SaveSystem.LoadFromSlot ( int  slotNumber)
inlinestatic

Loads a game from a slot.

◆ LoadGame()

static void PixelCrushers.SaveSystem.LoadGame ( SavedGameData  savedGameData)
inlinestatic

Loads the scene recorded in the saved game data (if saveCurrentScene is true) and applies the saved game data to it.

Parameters
savedGameData

◆ LoadGameFromSlot()

void PixelCrushers.SaveSystem.LoadGameFromSlot ( int  slotNumber)
inline

Loads a game from a slot using the storage provider on the Save System GameObject.

Parameters
slotNumber

◆ LoadScene()

static void PixelCrushers.SaveSystem.LoadScene ( string  sceneNameAndSpawnpoint)
inlinestatic

Loads a scene, optionally moving the player to a specified spawnpoint.

If the scene name starts with "index:" followed by an index number, this method loads the scene by build index number.

Parameters
sceneNameAndSpawnpointScene name, followed by an optional spawnpoint separated by '@'.

◆ LoadSceneAtSpawnpoint()

void PixelCrushers.SaveSystem.LoadSceneAtSpawnpoint ( string  sceneNameAndSpawnpoint)
inline

Loads a scene, optionally positioning the player at a specified spawnpoint.

Parameters
sceneNameAndSpawnpointA string containing the name of the scene to load, optionally followed by "@spawnpoint" where "spawnpoint" is the name of a GameObject in that scene. The player will be spawned at that GameObject's position.

◆ OnLevelWasLoaded()

void PixelCrushers.SaveSystem.OnLevelWasLoaded ( int  level)
inline

◆ RecordSavedGameData()

static SavedGameData PixelCrushers.SaveSystem.RecordSavedGameData ( )
inlinestatic

Records the current scene's savers' data into the SaveSystem's internal saved game data cache.

Returns

◆ RegisterSaver()

static void PixelCrushers.SaveSystem.RegisterSaver ( Saver  saver)
inlinestatic

◆ ResetGameState()

static void PixelCrushers.SaveSystem.ResetGameState ( )
inlinestatic

Clears the SaveSystem's saved game data cache.

Same as RestartGame except it doesn't load a scene after resetting.

Parameters
startingSceneName

◆ RestartGame()

static void PixelCrushers.SaveSystem.RestartGame ( string  startingSceneName)
inlinestatic

Clears the SaveSystem's saved game data cache and loads a starting scene.

Same as ResetGameState except loads a starting scene.

Parameters
startingSceneName

◆ SaveGameToSlot()

void PixelCrushers.SaveSystem.SaveGameToSlot ( int  slotNumber)
inline

Saves a game into a slot using the storage provider on the Save System GameObject.

Parameters
slotNumberSlot in which to store saved game data.

◆ SaversRestartGame()

static void PixelCrushers.SaveSystem.SaversRestartGame ( )
inlinestatic

Calls OnRestartGame on all savers.

◆ SaveToSlot()

static void PixelCrushers.SaveSystem.SaveToSlot ( int  slotNumber)
inlinestatic

Saves the current game to a slot.

◆ SaveToSlotImmediate()

static void PixelCrushers.SaveSystem.SaveToSlotImmediate ( int  slotNumber)
inlinestatic

Saves the current game to a slot synchronously and immediately.

◆ SceneLoadedDelegate()

delegate void PixelCrushers.SaveSystem.SceneLoadedDelegate ( string  sceneName,
int  sceneIndex 
)

◆ Serialize()

static string PixelCrushers.SaveSystem.Serialize ( object  data)
inlinestatic

Returns a serialized version of an object using whatever serializer is assigned to the SaveSystem (JSON by default).

◆ UnloadAdditiveScene()

static void PixelCrushers.SaveSystem.UnloadAdditiveScene ( string  sceneName)
inlinestatic

Unloads a previously additively-loaded scene.

Parameters
sceneNameScene to unload

◆ UnloadAdditiveSceneInternal()

static void PixelCrushers.SaveSystem.UnloadAdditiveSceneInternal ( string  sceneName)
inlinestatic

◆ UnloadAllAdditiveScenes()

static void PixelCrushers.SaveSystem.UnloadAllAdditiveScenes ( )
inlinestatic

Unloads all previously additively-loaded scenes.

◆ UnregisterSaver()

static void PixelCrushers.SaveSystem.UnregisterSaver ( Saver  saver)
inlinestatic

◆ UpdateSaveData()

static void PixelCrushers.SaveSystem.UpdateSaveData ( Saver  saver,
string  data 
)
inlinestatic

Updates the SaveSystem's internal saved game data cache with data for a specific saver.

Parameters
saver
data

◆ ValidateSceneNameDelegate()

delegate string PixelCrushers.SaveSystem.ValidateSceneNameDelegate ( string  sceneName,
SceneValidationMode  sceneValidationMode 
)

Member Data Documentation

◆ LastSavedGameSlotPlayerPrefsKey

const string PixelCrushers.SaveSystem.LastSavedGameSlotPlayerPrefsKey = "savedgame_lastSlotNum"
static

Stores an int indicating the slot number of the most recently saved game.

◆ NoSceneIndex

const int PixelCrushers.SaveSystem.NoSceneIndex = -1
static

◆ validateNameScene

ValidateSceneNameDelegate PixelCrushers.SaveSystem.validateNameScene = null
static

Invoked before loading a scene by name.

Should return the sceneName, or a different scene if the sceneName isn't valid (e.g., was renamed or removed from build settings), or a blank string to not load any scene.

Property Documentation

◆ addedScenes

List<string> PixelCrushers.SaveSystem.addedScenes
staticget

Scenes that have been loaded additively.

◆ allowNegativeSlotNumbers

bool PixelCrushers.SaveSystem.allowNegativeSlotNumbers
getset

Allow the use of negative slot numbers.

◆ autoUnloadAdditiveScenes

bool PixelCrushers.SaveSystem.autoUnloadAdditiveScenes
staticgetset

When changing scenes, automatically unload all additively-loaded scenes.

◆ currentAsyncOperation

AsyncOperation PixelCrushers.SaveSystem.currentAsyncOperation
staticgetset

Current asynchronous scene load operation, or null if none.

Loading scenes can use this value to update a progress bar.

◆ currentSavedGameData

SavedGameData PixelCrushers.SaveSystem.currentSavedGameData
staticgetset

The saved game data recorded by the last call to SaveToSlot, LoadScene, or RecordSavedGameData.

Note: This saved game data stays in memory until you clear it by using RestartGame() or ResetGameState(), or by loading a saved game.

◆ currentSceneIndex

int PixelCrushers.SaveSystem.currentSceneIndex
staticget

Build index of the current scene.

◆ debug

bool PixelCrushers.SaveSystem.debug
staticgetset

◆ framesToWaitBeforeApplyData

int PixelCrushers.SaveSystem.framesToWaitBeforeApplyData
staticgetset

When loading a game/scene, wait this many frames before applying saved data to allow other scripts to initialize first.

◆ framesToWaitBeforeSaveDataAppliedEvent

int PixelCrushers.SaveSystem.framesToWaitBeforeSaveDataAppliedEvent
staticgetset

If a saver requires additional frames after ApplyData() before the saveDataApplied() event should be called, set this property.

Note: This value is reset to zero after every call to ApplySavedGameData.

◆ hasInstance

bool PixelCrushers.SaveSystem.hasInstance
staticget

Checks if an instance already exists, without also implicitly creating one.

◆ instance

SaveSystem PixelCrushers.SaveSystem.instance
staticget

◆ maxSaveSlot

int PixelCrushers.SaveSystem.maxSaveSlot
staticgetset

Highest save slot number allowed.

◆ playerSpawnpoint

GameObject PixelCrushers.SaveSystem.playerSpawnpoint
staticgetset

Where the player should spawn in the current scene.

◆ saveCurrentScene

bool PixelCrushers.SaveSystem.saveCurrentScene
staticgetset

When loading a game, load the scene that the game was saved in.

◆ sceneTransitionManager

SceneTransitionManager PixelCrushers.SaveSystem.sceneTransitionManager
staticget

Reference to the SceneTransitionManager in the SaveSystem's hierarchy, if present.

◆ serializer

DataSerializer PixelCrushers.SaveSystem.serializer
staticget

Reference to the DataSerializer in the SaveSystem's hierarchy.

SaveSystem will use it to serialize and deserialize saved game data.

◆ storer

SavedGameDataStorer PixelCrushers.SaveSystem.storer
staticget

Reference to the SavedGameDataStorer in the SaveSystem's hierarchy.

SaveSystem will use it to store and retrieve saved game data.

◆ version

int PixelCrushers.SaveSystem.version
staticgetset

Optional saved game version number of your choosing.

Version number is included in saved game files.

Event Documentation

◆ loadEnded

System.Action PixelCrushers.SaveSystem.loadEnded = delegate { }
static

Invoked when finished loading a game.

◆ loadStarted

System.Action PixelCrushers.SaveSystem.loadStarted = delegate { }
static

Invoked when starting to load a game.

If assigned, waits one frame before starting the load to allow UIs to update.

◆ saveDataApplied

System.Action PixelCrushers.SaveSystem.saveDataApplied = delegate { }
static

Invoked after ApplyData() has been called on all savers.

◆ saveEnded

System.Action PixelCrushers.SaveSystem.saveEnded = delegate { }
static

Invoked when finished saving a game.

◆ saveStarted

System.Action PixelCrushers.SaveSystem.saveStarted = delegate { }
static

Invoked when starting to save a game.

If assigned, waits one frame before starting the save to allow UIs to update.

◆ sceneLoaded

SceneLoadedDelegate PixelCrushers.SaveSystem.sceneLoaded = delegate { }
static

Invoked after a scene has been loaded.


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