Getting Started

Add the namespace reference

C#
using CI.QuickSave;

Writing

There are a few different ways of writing files depending on the scenario

Use QuickSaveWriter to write one or more items to a root under different keys

C#
// Root / key names can be any identifier you like // Items saved under keys can be simple primitives as in this example or complex objects // You can write as many or as few keys as you like // Call commit as the last action to persist the changes to file var writer = QuickSaveWriter.Create("Player"); writer.Write("Points", 1600); writer.Write("Coins", 56); writer.Write("Lives", 5); writer.Write("Name", "John Doe"); writer.Commit(); // You can also chain writes and commits together for readability writer.Write("Points", 1600) .Write("Coins", 56) .Write("Lives", 5) .Write("Name", "John Doe") .Commit();

Use QuickSaveRaw to write files that contain text or binary content such as images

C#
// These can be used to write any arbitrary data to file, note that unlike the above you must specify a file extension here QuickSaveRaw.SaveString("File.txt", aString); QuickSaveRaw.SaveBytes("File.png", aByteArray);

Reading

There are a few different ways of reading files depending on the scenario

Use QuickSaveReader to read one or more items from a root

C#
// Here we read the data we saved in the section above var reader = QuickSaveReader.Create("Player"); var points = reader.Read<int>("Points"); var coins = reader.Read<int>("Coins"); var lives = reader.Read<int>("Lives"); var name = reader.Read<string>("Name"); // It's also possible to chain reads by supplying a callback int points; int coins; int lives; string name; reader.Read<int>("Points", r => points = r) .Read<int>("Coins", r => coins = r) .Read<int>("Lives", r => lives = r) .Read<string>("Name", r => name = r);

Use QuickSaveRaw to read or write files that contain text, binary content such as images, or Unity resources

C#
QuickSaveRaw.SaveString("Filename.txt", aString); QuickSaveRaw.SaveBytes("Filename.txt", aByteArray); QuickSaveRaw.LoadString("File.txt"); QuickSaveRaw.LoadBytes("File.png"); QuickSaveRaw.LoadResource<TextAsset>("Filename"); // Don't specify a file extension

Encryption / Compression

We can encrypt and or compress the data that gets saved by creating a QuickSaveWriter with the correct settings. If you wish to use either they must be set the first time you create the root

C#
var writer = QuickSaveWriter.Create("Player", new QuickSaveSettings() { SecurityMode = SecurityMode.Aes, Password = "Pasword123", CompressionMode = CompressionMode.Gzip });

When the data gets read back in you must specify the same settings

C#
var writer = QuickSaveReader.Create("Player", new QuickSaveSettings() { SecurityMode = SecurityMode.Aes, Password = "Pasword123", CompressionMode = CompressionMode.Gzip });

Ignoring fields

If you don't want to save all properties on an object you can add an ignore attribute to them

C#
public class MyClass { [JsonIgnore] public string Text { get; set; } }

Csv

Use QuickSaveCSV to save and load csv files

C#
var csv = new QuickSaveCSV(); csv.SetCell(0, 0, "Test"); csv.SetCell(3, 5, "Yooooo"); csv.SetCell(0, 10, 32); csv.SetCell(8, 3, true); csv.SetCell(8, 0, 23.567); csv.Save($"{Application.persistentDataPath}/test.csv"); csv = QuickSaveCsv.Load($"{Application.persistentDataPath}/test.csv"); var cell = csv.GetCell(0, 0); csv.DeleteRow(8);