Contents

Lix Save System – Full Documentation

Author: SillyLix
asset version: 1.0.0
License: License
Unity Version: 6000.0.61f1+
download (itch.io): itch.io


Overview

The Lix Save System is a flexible data persistence solution for Unity projects. It allows developers to easily save and load common data types such as int, float, string, bool, Vector2, Vector3, and lists for int, float, string, bool and double.

The system is built using Unity’s JsonUtility for serialization, combined with optional XOR-based encryption.


1. Core Classes

🔹 GameData

Holds all serialized information for your save file.

public class GameData
{
    public SerializedDictionary<string, int> intData;
    public SerializedDictionary<string, float> floatData;
    public SerializedDictionary<string, string> stringData;
    public SerializedDictionary<string, bool> boolData;
    public SerializedDictionary<string, double> doubleData;
    public GameDataConf gameDataConf;
}

Description:


🔹 SerializedDictionary<TKey, TValue>

A serializable dictionary implementation compatible with Unity’s serialization system.

It converts keys and values into two synchronized List<T> objects before serialization, then reconstructs them after deserialization.

public void OnBeforeSerialize()
{
    keys.Clear();
    values.Clear();
    foreach (var pair in this)
    {
        keys.Add(pair.Key);
        values.Add(pair.Value);
    }
}

public void OnAfterDeserialize()
{
    Clear();
    for (int i = 0; i < keys.Count; i++)
        Add(keys[i], values[i]);
}

2. SaveSystem Class

The static SaveSystem class provides all methods for saving, loading, and managing data.

Methods:

🧩 LixSave(ref GameData data, string key, object value)

Saves any supported type to your GameData object and writes it to disk.

Supported types: int, float, string, bool, double, Vector2, Vector3, List<T> (int/float/string/bool)

SaveSystem.LixSave(ref gameData, "PlayerScore", 1500);
SaveSystem.LixSave(ref gameData, "PlayerName", "Lix");

🧩 LixLoad<T>(GameData data, string name)

Loads data of type T from file or memory. Returns default(T) if not found.

int score = SaveSystem.LixLoad<int>(gameData, "PlayerScore");
Vector3 pos = SaveSystem.LixLoad<Vector3>(gameData, "PlayerPosition");

🧩 LixHasKey(GameData data, string key)

Checks if a key exists in the save data.

if (SaveSystem.LixHasKey(gameData, "PlayerHealth")) {
    Debug.Log("Health data exists!");
}

🧩 LixRemove(GameData data, string key)

Removes a saved key from the dictionary.

SaveSystem.LixRemove(gameData, "PlayerScore");

🧩 LixClearAllData(GameData data)

Completely clears all stored data (does not delete file).

SaveSystem.LixClearAllData(gameData);

🧩 LixSaveGameData(ref GameData data)

Manually writes all current GameData contents to the save file.


🧩 LixLoadGameData(GameData data)

Loads save file from disk and populates your GameData instance.


3. Example Usage

public class Example : MonoBehaviour
{
    private GameData gameData;

    void Start()
    {
        gameData = new GameData();
        gameData.gameDataConf.SetFileName(gameData, "PlayerSave");
        gameData.gameDataConf.SetEncryption(gameData, true);
        gameData.gameDataConf.SetEncryptionKey(gameData, "CustomKey123");

        SaveSystem.LixSave(ref gameData, "PlayerName", "Lix");
        SaveSystem.LixSave(ref gameData, "PlayerScore", 99);

        string name = SaveSystem.LixLoad<string>(gameData, "PlayerName");
        int score = SaveSystem.LixLoad<int>(gameData, "PlayerScore");
    }
}

4. Example Input Controls (Lix_Example_CODE.cs)

This code shows many functionality of the system. It is recommended for you to reed it. you can use this code to see how the system work.

To use it simply add this code to Empty GameObject and you can use the following keys to do different things:


5. Encryption Notes

The save files can be optionally XOR-encrypted using your own key. This prevents basic tampering but is not meant for high-security use cases.

gameData.gameDataConf.SetEncryption(gameData, true);
gameData.gameDataConf.SetEncryptionKey(gameData, "MySecretKey");

If you want to use other encryption system:


go to SaveSystem.cs then find function: LixSaveGameData() and then you can change the code
also go to function LixLoadGameData() and change the decryption code.


LixSaveGameData():


if (isEncrypted)
{
    byte[] plainBytes = System.Text.Encoding.UTF8.GetBytes(json);
    byte[] keyBytes = System.Text.Encoding.UTF8.GetBytes(encryptionKey);
    byte[] result = new byte[plainBytes.Length];
    
    for (int i = 0; i < json.Length; i++) 
    {
    result[i]=(byte)(plainBytes[i] ^ keyBytes[i % keyBytes.Length]); 
}
    json=System.Convert.ToBase64String(result);  }
    
    File.WriteAllText(path, json);
    

LixLoadGameData():


// Decrypt if necessary (uses simple XOR encryption for demonstration)
if (data.gameDataConf.GetIsEncrypted(data))
{

    string encryptionKey = data.gameDataConf.GetEncryptionKey(data);

    // to decrypt, reverse the XOR operation
    // turn the base64 string back to bytes
    byte[] encryptedBytes = System.Convert.FromBase64String(json);
    byte[] keyBytes = System.Text.Encoding.UTF8.GetBytes(encryptionKey);
    byte[] result = new byte[encryptedBytes.Length];

    for (int i = 0; i < encryptedBytes.Length; i++) 
    { 
        result[i]=(byte)(encryptedBytes[i] ^ keyBytes[i % keyBytes.Length]); 
    }
    
    json=System.Text.Encoding.UTF8.GetString(result); 
} 

loaded=JsonUtility.FromJson(json);
    

6. License

Overview: This license governs use of the provided assets and the rights granted to the Licensee.

1. Definitions

Asset(s): The files, code, and other materials provided by the Licensor.

End Product: A game, application, or other finished product in which the Asset is incorporated and distributed to end users.

2. Grant of License

The Licensor grants the Licensee a worldwide, non-exclusive, non-transferable license to:

3. Restrictions

Licensee may not:

4. Attribution

Attribution is NOT required for this asset, but it is very much so appreciated.

5. Ownership

Ownership: The Licensor retains all copyright and moral rights in the Asset. The Licensee receives only the rights expressly granted in this license.

6. Termination

Violation of any term of this license automatically terminates the rights granted. Upon termination the Licensee must cease using the Asset and remove it from any End Product distribution.

7. Disclaimer

Assets are provided "as is" without warranty of any kind. The Licensor is not responsible for any damages arising from the use of the Asset.