Giter Club home page Giter Club logo

unity-saver's Introduction

Unity-Saver

npm License Stand With Ukraine

Encrypted local data storage in Unity runtime on any platform. Thread safe, Unity-Saver uses dedicated non-main thread for Read/Write operations with files. Data can be stored in different locations:

  • Persistant - Regular Unity PersistantDataStorage location
    • ✔️ iOS
    • ✔️ Android
    • ✔️ Standalone
  • Local - current location of executed app
    • iOS
    • Android
    • ✔️ Standalone
  • Custom - any path on your own
    • iOS
    • Android
    • ✔️ Standalone

Unity Saver Settings

How to install - Option 1 (RECOMMENDED)

How to install - Option 2

{
  "dependencies": {
    "extensions.unity.saver": "1.0.8",
  },
  "scopedRegistries": [
    {
      "name": "Unity Extensions",
      "url": "https://registry.npmjs.org",
      "scopes": [
        "extensions.unity"
      ]
    }
  ]
}

Usage API

Usage is very simple, you have access to a data through Data property in saver class.

  • Data - current data with read & write permission (does not read and write from file)
  • DefaultData - access to default data, this data whould be taken on Load operation, only if file is missed or currupted
  • 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 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 need and do not worry about wasting CPU resources for continuously writing data into file.

How to use in MonoBehaviour

using Extensions.Saver;

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

How to use in ScriptableObject

using UnityEngine;
using Extensions.Saver;

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

    protected override void OnDataLoaded(TestData data)
    {
        
    }
}

How to use in C# class

using System;
using System.Threading.Tasks;
using Extensions.Saver;

public class TestClassSaver
{
    public Saver<TestData> saver;

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

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

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

unity-saver's People

Contributors

ivanmurzak avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.