An open API service indexing awesome lists of open source software.

https://github.com/ivanmurzak/unity-saver

Unity Saver extension provides ability to save any data type of any size in three different possible locations with device related encryption.
https://github.com/ivanmurzak/unity-saver

Last synced: 3 months ago
JSON representation

Unity Saver extension provides ability to save any data type of any size in three different possible locations with device related encryption.

Awesome Lists containing this project

README

        

# Unity-Saver
![npm](https://img.shields.io/npm/v/extensions.unity.saver) [![openupm](https://img.shields.io/npm/v/extensions.unity.saver?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/extensions.unity.saver/) ![License](https://img.shields.io/github/license/IvanMurzak/Unity-Saver) [![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)

Encrypted local data storage in Unity runtime on any platform. Thread safe, Unity-Saver uses a dedicated non-main thread for Read/Write operations with files.
Data can be stored in different locations:
- :white_check_mark: Persistent - Regular Unity PersistantDataStorage location
- ✔️ iOS
- ✔️ Android
- ✔️ Standalone
- :white_check_mark: Local - the current location of the executed app
- :x: iOS
- :x: Android
- ✔️ Standalone
- :white_check_mark: Custom - any path on your own
- :x: iOS
- :x: Android
- ✔️ Standalone

![Unity Saver Settings](https://imgur.com/0RQeUQg.gif)

# How to install - Option 1 (RECOMMENDED)
- Install [ODIN Inspector](https://odininspector.com/)
- [Install OpenUPM-CLI](https://github.com/openupm/openupm-cli#installation)
- Open a command line in Unity project folder
- `openupm add extensions.unity.saver`

# How to install - Option 2
- Install [ODIN Inspector](https://odininspector.com/)
- Add this code to /Packages/manifest.json
```json
{
"dependencies": {
"extensions.unity.saver": "1.0.9",
},
"scopedRegistries": [
{
"name": "package.openupm.com",
"url": "https://package.openupm.com",
"scopes": [
"extensions.unity.saver",
"com.cysharp",
"com.neuecc"
]
}
]
}
```

# Usage API
Usage is very simple, you have access to data through Data property in the saver class.
- Data - current data with read & write permission (does not read and write from file)
- DefaultData - access to default data, this data would be taken on Load operation, only if a file is missed or corrupted
- Load() - force to execute load from a file operation, returns async Task
- Save() - insta save current Data to a file, returns async Task
- SaveDelay() - put save operation in a queue, if the same file is going to be saved twice, just a single call will be executed. Very useful when data changes very often and required to call Save often as well. You may call SaveDelay as many times as needed and do not worry about wasting CPU resources for continuously writing data into a file.

# How to use in MonoBehaviour
```C#
using Extensions.Saver;

public class TestMonoBehaviourSaver : SaverMonoBehaviour
{
protected override string SaverPath => "TestDatabase";
protected override string SaverFileName => "testMonoBehaviour.data";
}
```

# How to use in ScriptableObject
```C#
using UnityEngine;
using Extensions.Saver;

[CreateAssetMenu(menuName = "Example (Saver)/Test Scriptable Object Saver", fileName = "Test Scriptable Object Saver", order = 0)]
public class TestScriptableObjectSaver : SaverScriptableObject
{
protected override string SaverPath => "TestDatabase";
protected override string SaverFileName => "testScriptableObject.data";

protected override void OnDataLoaded(TestData data)
{

}
}
```

# How to use in C# class
```C#
using System;
using System.Threading.Tasks;
using Extensions.Saver;

public class TestClassSaver
{
public Saver saver;

// Should be called from the main thread, in the Awake or Start method for example
public void Init()
{
saver = new Saver("TestDatabase", "testClass.data", new TestData());
}

public TestData Load() => saver?.Load();

public async Task Save(Action onComplete = null) => await saver?.Save(onComplete);
}
```