Async Load/Save Local Data With Compression, Encryption And Integrity Check
'Local Data' is a module of 'Game:Work' dedicated to read and write local files asynchronously.
- Fully asynchronous read, load and cancel.
- Integrity check using MD5, SHA-1, SHA-256 or SHA-512 algorithms.
- Compression / decompression using algorithms: GZip, Zip or Brotli.
- Encryption / decryption using algorithms: AES, DES, RC2, DES or TripleDES.
- Supports typical Unity data such as: Vector, Quaternion, Color, etc.
- Unity 2020.3 or higher.
- Game:Work Core.
- Game:Work Foundation.
- Test Framework 1.1.31 or higher.
- Open the manifest.json file of your Unity project.
- In the section "dependencies" add:
{
...
"dependencies":
{
...
"FronkonGames.GameWork.Modules.LocalData": "git+https://github.com/FronkonGames/GameWork-Local-Data.git",
"FronkonGames.GameWork.Core": "git+https://github.com/FronkonGames/GameWork-Core.git",
"FronkonGames.GameWork.Foundation": "git+https://github.com/FronkonGames/GameWork-Foundation.git"
}
...
}
First clone the dependencies inside your Assets folder:
git clone https://github.com/FronkonGames/GameWork-Foundation.git
git clone https://github.com/FronkonGames/GameWork-Core.git
Then clone the repository:
git clone https://github.com/FronkonGames/GameWork-Local-Data.git
Create a class inheriting from ILocalData and add the attribute Serializable:
[Serializable]
public class MyLocalData : ILocalData
{
public string Signature => "MySignature";
public string playerName = "Guybrush Threepwood";
public Vector3 position = new(0.0f, -10.0f, 0.0f);
}
To serialize it in the file 'Guy.brush':
localDataModule.Write(myLocalData, "Guy.brush", null, (result) =>
{
if (result == FileResult.Ok)
Debug.Log("Guybrush Threepwood saved!");
else
Debug.Error($"{result} writing 'Guy.brush'.");
});
To deserialise the file 'Guy.brush' into an object:
MyLocalData myLocaldata = null;
localDataModule.Read<MyLocalData>("Guy.brush", null, (result, file) =>
{
if (result == FileResult.Ok)
myLocalData = file;
else
Debug.Error($"{result} reading 'Guy.brush'.");
});
Code released under MIT License.