SaveSystemManager#
- NAMESPACE:
UnityUtils.ScriptUtils.SaveSystem
The SaveSystemManager script is used in turn with other save systems to assist with save systems. This script is used to call the Save() and Load() functions in all scripts inheriting ISaveableData. Also includes some functions that help with getting SaveSlots and SaveDatas
Example Usage#
using UnityEngine;
using UnityUtils.ScriptUtils.SaveSystem;
public class ExampleScript : MonoBehaviour
{
// Create a save slot with the example type "GameData"
SaveSlot saveFile = new SaveSlot("save", SaveSystemManager.CreateSaveData<GameData>(path))
void Start()
{
// Calls all the ISaveableData objects and their Save() function
SaveSystemManager.SaveGame(saveFile);
// Calls all the ISaveableData objects and their Load() function
SaveSystemManager.LoadGame(saveFile);
// Deletes the save slot
SaveSystemManager.DeleteSaveFile(saveFile);
}
}
Functions#
- UnityUtils.ScriptUtils.SaveSystem.SaveSystemManager
Public Static Functions
-
void SaveGame(SaveSlot saveSlot)#
Calls ISaveableData.SaveData<T>(T) on every script inheriting ISaveableData.
- Parameters:
saveSlot – Save slot to save data from ISaveableData’s
-
void LoadGame(SaveSlot saveSlot)#
Calls ISaveableData.LoadData<T>(T) on every script inheriting ISaveableData.
- Parameters:
saveSlot – Save slot to load data from all the ISaveableData’s
-
void DeleteSaveSlot(SaveSlot saveSlot)#
Delete a save slot.
- Parameters:
saveSlot – Save slot to delete
-
List<ISaveableData> FindAllDataPersistanceObjects()#
Gets all ISaveableData to call functions on.
- Returns:
List of all objects with ISaveableData attached
-
Dictionary<string, SaveSlot> LoadAllSaveSlots()#
Loads all save slots from the SaveSystemUtils.SAVE_FILES_NAME directory, if none exist one is created.
- Returns:
Dictionary of the save slot name and SaveSlot
-
template<>
SaveData CreateSaveData<T>(string fileName)# Registers a new SaveDataID to the registry to be referenced later.
- Template Parameters:
T – data type to encode, must inherit SaveData
- Parameters:
fileName – The file name of the save object
- Returns:
The SaveDataID with its filled in parameters
-
SaveSlot GetMostRecentSave(List<SaveSlot> saveSlots)#
Grabs the most recent save in a list of SaveSlot.
- Parameters:
saveSlots – Save slots to sort through
- Returns:
Most recently saved slot
-
void SaveAllSaveableData(SaveData dataToSave, List<ISaveableData> saveTo)#
Calls ISaveableData.SaveData<T>(T) on all the objects in saveTo .
- Parameters:
dataToSave – Data object to pass into the all the saveToISaveableData’s
saveTo – All the ISaveableData objects that get ISaveableData.SaveData<T>(T) called on it, with dataToSave passed into it
-
void SaveAllSaveableData(SaveData dataToSave)#
Calls SaveAllSaveableData(SaveData, List<ISaveableData>), and calls FindAllDataPersistanceObjects as the List<ISaveableData>.
- Parameters:
dataToSave – Data object to pass into the all the FindAllDataPersistanceObjects() ISaveableData’s
-
void LoadAllSaveableData(SaveData dataToLoad, List<ISaveableData> loadFrom)#
Calls ISaveableData.LoadData<T>(T) on all the objects in loadFrom .
- Parameters:
dataToLoad – Data object to pass into the all the loadFromISaveableData’s
loadFrom – All the ISaveableData objects that get ISaveableData.LoadData<T>(T) called on it, with dataToLoad passed into it
-
void LoadAllSaveableData(SaveData dataToLoad)#
Calls SaveAllSaveableData(SaveData, List<ISaveableData>), and calls FindAllDataPersistanceObjects as the List<ISaveableData>.
- Parameters:
dataToLoad – Data object to pass into the all the FindAllDataPersistanceObjects() ISaveableData’s
Public Static Attributes
-
bool outputLogs = true
If true will output Debug.Log()’s on Save/Load.
-
void SaveGame(SaveSlot saveSlot)#