JsonSaveSystem#
- NAMESPACE:
UnityUtils.ScriptUtils.SaveSystem
The JsonSaveSystem script is used in turn with other save systems to assist with save systems. This script writes and loads data from json files
Tip
To create a good encryption key, just spam your keyboard and make it decently long. (Ex. “]fdS()fv.cx?Fjh*()S)(12fjdPGIO()GjvnFLKGj”)
Warning
Do not share your encryption key, otherwise it will be incredibly easy to decrypt and encrypt save files
Example Usage#
using UnityEngine;
using UnityUtils.ScriptUtils.SaveSystem;
public class ExampleScript : MonoBehaviour
{
List<SaveSlot> saveDatas = new();
void Start()
{
// Set encryption key for encrypting data (DO NOT SHARE THIS KEY ANYWHERE)
JsonSaveSystem.SetEncryptionKey("YourEncryptionKey");
// Use the encryption key
JsonSaveSystem.UseEncryption(true);
// Serializes all the save slots, but note: do not use this, call SaveSystemManager instead to properly save and load data to ISaveable's
for (SaveSlot data in saveDatas)
{
JsonSaveSystem.Save(data);
}
// Deserializes all the save files back into their SaveSlot counterparts
List<SaveSlot> loadedData = JsonSaveSystem.Load(saveDatas);
}
}
Functions#
- UnityUtils.ScriptUtils.SaveSystem.JsonSaveSystem
Public Static Functions
-
void Save(SaveData saveData)#
Serializes the inputted saveData into SaveDataID.fileName in a json format.
- Parameters:
saveData – saveData of the file to be saved
-
SaveSlot Load(SaveSlot saveSlot)#
Loads all save files in a save slot.
- Parameters:
saveSlot – Save slot to load
- Returns:
-
SaveData LoadSingleSaveFile(SaveData saveData, SaveSlot saveSlot)#
Loads a single save slot file.
- Parameters:
saveData – Save data to load
saveSlot – Save slot to load it to
- Returns:
-
void Delete(SaveSlot saveSlot)#
Deletes the inputted save slot’s save files.
- Parameters:
saveSlot – SaveSlot to delete from the file system
-
void SetEncryptionKey(string key)#
Sets the encryption key for file encryption.
- Parameters:
key – Key to set the encryptionKey to
-
void UseEncryption(bool encryption)#
Sets the encryption bool.
- Parameters:
encryption – Bool to set useEncryption to
-
string EncryptDecrypt(string data)#
Encrypts data via an XOR shift of data using the encryptionKey.
Make sure you SetEncryptionKey(string)
- Parameters:
data – Data to encrypt
- Returns:
Encrypted data
-
string GetJsonStringData(string path)#
Grabs the string of data inside a json file via a path.
- Parameters:
path – Full path to the save file
- Returns:
A string of all the data in the json
-
SaveData GetSaveData(string json)#
Deserializes a json string file.
Use GetJsonStringData(string) to get a json string from a path
- Parameters:
json – Json to deserialize
- Returns:
Deserialized save data
-
string SaveSaveData(SaveData saveData)#
Serializes a SaveData and return the string of serialized data.
- Parameters:
saveData – Data to serialize
- Returns:
String of serialized data
-
void CreateRootSaveDataIfNotExisting()#
Will create SaveSystemUtils.GetSaveSlotRootPath() if it does not exist.
Public Static Attributes
-
bool outputLogs = true#
If true will output Debug.Log()’s on Save/Load.
-
void Save(SaveData saveData)#