This is the main Save System class. More...
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. | |
This is the main Save System class.
It runs as a singleton MonoBehaviour and provides static methods to save and load games.
|
inlinestatic |
Applies the most recently recorded saved game data.
|
inlinestatic |
Applies the saved game data to the savers in the current scene.
savedGameData | Saved game data. |
|
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.
|
inlinestatic |
Clears the SaveSystem's internal saved game data cache.
|
inlinestaticprotected |
|
inlinestatic |
Deletes the saved game in the specified slot.
|
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).
T | The type of the object. |
s | The object's serialized data. |
data | Optional preallocated object to serialize data into. |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Returns true if there is a saved game in the specified slot.
|
inlinestatic |
Additively loads another scene.
sceneName | Scene to additively load. |
|
inlinestatic |
|
inlinestatic |
Loads a game from a slot.
|
inlinestatic |
Loads the scene recorded in the saved game data (if saveCurrentScene is true) and applies the saved game data to it.
savedGameData |
|
inline |
Loads a game from a slot using the storage provider on the Save System GameObject.
slotNumber |
|
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.
sceneNameAndSpawnpoint | Scene name, followed by an optional spawnpoint separated by '@'. |
|
inline |
Loads a scene, optionally positioning the player at a specified spawnpoint.
sceneNameAndSpawnpoint | A 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. |
|
inline |
|
inlinestatic |
Records the current scene's savers' data into the SaveSystem's internal saved game data cache.
|
inlinestatic |
|
inlinestatic |
Clears the SaveSystem's saved game data cache.
Same as RestartGame except it doesn't load a scene after resetting.
startingSceneName |
|
inlinestatic |
Clears the SaveSystem's saved game data cache and loads a starting scene.
Same as ResetGameState except loads a starting scene.
startingSceneName |
|
inline |
Saves a game into a slot using the storage provider on the Save System GameObject.
slotNumber | Slot in which to store saved game data. |
|
inlinestatic |
Calls OnRestartGame on all savers.
|
inlinestatic |
Saves the current game to a slot.
|
inlinestatic |
Saves the current game to a slot synchronously and immediately.
delegate void PixelCrushers.SaveSystem.SceneLoadedDelegate | ( | string | sceneName, |
int | sceneIndex | ||
) |
|
inlinestatic |
Returns a serialized version of an object using whatever serializer is assigned to the SaveSystem (JSON by default).
|
inlinestatic |
Unloads a previously additively-loaded scene.
sceneName | Scene to unload |
|
inlinestatic |
|
inlinestatic |
Unloads all previously additively-loaded scenes.
|
inlinestatic |
|
inlinestatic |
Updates the SaveSystem's internal saved game data cache with data for a specific saver.
saver | |
data |
delegate string PixelCrushers.SaveSystem.ValidateSceneNameDelegate | ( | string | sceneName, |
SceneValidationMode | sceneValidationMode | ||
) |
|
static |
Stores an int indicating the slot number of the most recently saved game.
|
static |
|
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.
|
staticget |
Scenes that have been loaded additively.
|
getset |
Allow the use of negative slot numbers.
|
staticgetset |
When changing scenes, automatically unload all additively-loaded scenes.
|
staticgetset |
Current asynchronous scene load operation, or null if none.
Loading scenes can use this value to update a progress bar.
|
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.
|
staticget |
Build index of the current scene.
|
staticgetset |
|
staticgetset |
When loading a game/scene, wait this many frames before applying saved data to allow other scripts to initialize first.
|
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.
|
staticget |
Checks if an instance already exists, without also implicitly creating one.
|
staticget |
|
staticgetset |
Highest save slot number allowed.
|
staticgetset |
Where the player should spawn in the current scene.
|
staticgetset |
When loading a game, load the scene that the game was saved in.
|
staticget |
Reference to the SceneTransitionManager in the SaveSystem's hierarchy, if present.
|
staticget |
Reference to the DataSerializer in the SaveSystem's hierarchy.
SaveSystem will use it to serialize and deserialize saved game data.
|
staticget |
Reference to the SavedGameDataStorer in the SaveSystem's hierarchy.
SaveSystem will use it to store and retrieve saved game data.
|
staticgetset |
Optional saved game version number of your choosing.
Version number is included in saved game files.
|
static |
Invoked when finished loading a game.
|
static |
Invoked when starting to load a game.
If assigned, waits one frame before starting the load to allow UIs to update.
|
static |
Invoked after ApplyData() has been called on all savers.
|
static |
Invoked when finished saving a game.
|
static |
Invoked when starting to save a game.
If assigned, waits one frame before starting the save to allow UIs to update.
|
static |
Invoked after a scene has been loaded.