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 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. More...
 
void LoadGameFromSlot (int slotNumber)
 Loads a game from a slot using the storage provider on the Save System GameObject. More...
 
void LoadSceneAtSpawnpoint (string sceneNameAndSpawnpoint)
 Loads a scene, optionally positioning the player at a specified spawnpoint. More...
 

Static Public Member Functions

static string GetCurrentSceneName ()
 
static int GetCurrentSceneIndex ()
 
static bool HasSavedGameInSlot (int slotNumber)
 Returns true if there is a saved game in the specified slot. More...
 
static void DeleteSavedGameInSlot (int slotNumber)
 Deletes the saved game in the specified slot. More...
 
static void SaveToSlot (int slotNumber)
 Saves the current game to a slot. More...
 
static void LoadFromSlot (int slotNumber)
 Loads a game from a slot. More...
 
static void RegisterSaver (Saver saver)
 
static void UnregisterSaver (Saver saver)
 
static void ClearSavedGameData ()
 Clears the SaveSystem's internal saved game data cache. More...
 
static SavedGameData RecordSavedGameData ()
 Records the current scene's savers' data into the SaveSystem's internal saved game data cache. More...
 
static void UpdateSaveData (Saver saver, string data)
 Updates the SaveSystem's internal saved game data cache with data for a specific saver. More...
 
static void ApplySavedGameData (SavedGameData savedGameData)
 Applies the saved game data to the savers in the current scene. More...
 
static void ApplySavedGameData ()
 Applies the most recently recorded saved game data. More...
 
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. More...
 
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. More...
 
static void LoadScene (string sceneNameAndSpawnpoint)
 Loads a scene, optionally moving the player to a specified spawnpoint. More...
 
static void RestartGame (string startingSceneName)
 Clears the SaveSystem's saved game data cache and loads a starting scene. More...
 
static string Serialize (object data)
 Returns a serialized version of an object using whatever serializer is assigned to the SaveSystem (JSON by default). More...
 
static T Deserialize< T > (string s, T data=default(T))
 Deserializes a previously-serialized string representation of an object back into an object. More...
 

Public Attributes

const int NoSceneIndex = -1
 
const string LastSavedGameSlotPlayerPrefsKey = "savedgame_lastSlotNum"
 Stores an int indicating the slot number of the most recently saved game. More...
 

Properties

static bool saveCurrentScene [get, set]
 When loading a game, load the scene that the game was saved in. More...
 
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. More...
 
static bool debug [get, set]
 
static SaveSystem instance [get]
 
static SceneTransitionManager sceneTransitionManager [get]
 
static SavedGameData currentSavedGameData [get]
 The saved game data recorded by the last call to SaveToSlot, LoadScene, or RecordSavedGameData. More...
 
static GameObject playerSpawnpoint [get, set]
 Where the player should spawn in the current scene. More...
 
static int currentSceneIndex [get]
 Build index of the current scene. More...
 

Events

static SceneLoadedDelegate sceneLoaded = delegate { }
 Invoked after a scene has been loaded. More...
 
static System.Action saveStarted = delegate { }
 Invoked when starting to save a game. More...
 
static System.Action saveEnded = delegate { }
 Invoked when finished saving a game. More...
 
static System.Action loadStarted = delegate { }
 Invoked when starting to load a game. More...
 
static System.Action loadEnded = delegate { }
 Invoked when finished loading a game. More...
 

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

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

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

Parameters
savedGameDataSaved game data.
static void PixelCrushers.SaveSystem.ApplySavedGameData ( )
static

Applies the most recently recorded saved game data.

static void PixelCrushers.SaveSystem.BeforeSceneChange ( )
static

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 PixelCrushers.SaveSystem.ClearSavedGameData ( )
static

Clears the SaveSystem's internal saved game data cache.

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

Deletes the saved game in the specified slot.

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

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.
static int PixelCrushers.SaveSystem.GetCurrentSceneIndex ( )
static
static string PixelCrushers.SaveSystem.GetCurrentSceneName ( )
static
static bool PixelCrushers.SaveSystem.HasSavedGameInSlot ( int  slotNumber)
static

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

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

Loads a game from a slot.

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

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

Parameters
savedGameData
void PixelCrushers.SaveSystem.LoadGameFromSlot ( int  slotNumber)

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

Parameters
slotNumber
static void PixelCrushers.SaveSystem.LoadScene ( string  sceneNameAndSpawnpoint)
static

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

Parameters
sceneNameAndSpawnpointScene name, followed by an optional spawnpoint separated by '@'.
void PixelCrushers.SaveSystem.LoadSceneAtSpawnpoint ( string  sceneNameAndSpawnpoint)

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.
void PixelCrushers.SaveSystem.OnLevelWasLoaded ( int  level)
static SavedGameData PixelCrushers.SaveSystem.RecordSavedGameData ( )
static

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

Returns
static void PixelCrushers.SaveSystem.RegisterSaver ( Saver  saver)
static
static void PixelCrushers.SaveSystem.RestartGame ( string  startingSceneName)
static

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

Parameters
startingSceneName
void PixelCrushers.SaveSystem.SaveGameToSlot ( int  slotNumber)

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

Parameters
slotNumberSlot in which to store saved game data.
static void PixelCrushers.SaveSystem.SaveToSlot ( int  slotNumber)
static

Saves the current game to a slot.

delegate void PixelCrushers.SaveSystem.SceneLoadedDelegate ( string  sceneName,
int  sceneIndex 
)
static string PixelCrushers.SaveSystem.Serialize ( object  data)
static

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

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

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

Parameters
saver
data

Member Data Documentation

const string PixelCrushers.SaveSystem.LastSavedGameSlotPlayerPrefsKey = "savedgame_lastSlotNum"

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

const int PixelCrushers.SaveSystem.NoSceneIndex = -1

Property Documentation

SavedGameData PixelCrushers.SaveSystem.currentSavedGameData
staticget

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

int PixelCrushers.SaveSystem.currentSceneIndex
staticget

Build index of the current scene.

bool PixelCrushers.SaveSystem.debug
staticgetset
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.

SaveSystem PixelCrushers.SaveSystem.instance
staticget
GameObject PixelCrushers.SaveSystem.playerSpawnpoint
staticgetset

Where the player should spawn in the current scene.

bool PixelCrushers.SaveSystem.saveCurrentScene
staticgetset

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

SceneTransitionManager PixelCrushers.SaveSystem.sceneTransitionManager
staticget

Event Documentation

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

Invoked when finished loading a game.

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.

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

Invoked when finished saving a game.

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.

SceneLoadedDelegate PixelCrushers.SaveSystem.sceneLoaded = delegate { }
static

Invoked after a scene has been loaded.


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