All Projects → IntoTheDev → Save-System-for-Unity

IntoTheDev / Save-System-for-Unity

Licence: other
Save System for Unity with AOT (IL2CPP) and assets references support.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to Save-System-for-Unity

Csharp Eval Unity3d
C# Expression Parser for Unity3D
Stars: ✭ 102 (-12.07%)
Mutual labels:  unity-scripts, unity-asset
Apple Signin Unity
Unity plugin to support Sign In With Apple Id
Stars: ✭ 228 (+96.55%)
Mutual labels:  unity-scripts, unity-asset
Infinity Square Space
Infinity Square/Space. The prototype of the game is open source. Unity Asset.
Stars: ✭ 122 (+5.17%)
Mutual labels:  unity-scripts, unity-asset
Unity Assetpipeline Presentation
Unity project for "A Technical Deep-Dive into Unity's Asset Pipeline" presented at Develop: 2018
Stars: ✭ 31 (-73.28%)
Mutual labels:  unity-scripts, unity-asset
unity-puzzlesystem-asset
The asset for the Unity Engine that allows to quickly create customisable puzzles.
Stars: ✭ 21 (-81.9%)
Mutual labels:  unity-scripts, unity-asset
Awesome Unity Open Source On Github
A categorized collection of awesome Unity open source on GitHub (800+)
Stars: ✭ 1,124 (+868.97%)
Mutual labels:  unity-scripts, unity-asset
Nvjob Water Shader Simple And Fast
#NVJOB Simple Water Shaders. Free Unity Asset.
Stars: ✭ 172 (+48.28%)
Mutual labels:  unity-scripts, unity-asset
Savegamefree
Save Game Free is a free and simple but powerful solution for saving and loading game data in unity.
Stars: ✭ 279 (+140.52%)
Mutual labels:  unity-scripts, unity-asset
nvjob-sky-shader-simple-and-fast
#NVJOB Dynamic Sky. Sky Shaders. Free Unity Asset.
Stars: ✭ 103 (-11.21%)
Mutual labels:  unity-scripts, unity-asset
UnityHexagonLibrary2d
A library to manage 2D hexagonal tiles in Unity.
Stars: ✭ 58 (-50%)
Mutual labels:  unity-scripts, unity-asset
Savegamepro
A Complete and Powerful Save Game Solution for Unity (Game Engine)
Stars: ✭ 30 (-74.14%)
Mutual labels:  unity-scripts, unity-asset
UnityGlobalTextSystem
Allow the user to 'change' the default font in Unity from "Arial" to a font of their liking.
Stars: ✭ 21 (-81.9%)
Mutual labels:  unity-scripts, unity-asset
Restclient
🦄 Simple HTTP and REST client for Unity based on Promises, also supports Callbacks! 🎮
Stars: ✭ 675 (+481.9%)
Mutual labels:  unity-scripts, unity-asset
Fancyscrollview
[Unity] A scrollview component that can implement highly flexible animations.
Stars: ✭ 1,216 (+948.28%)
Mutual labels:  unity-scripts, unity-asset
Unity Script Collection
A maintained collection of useful & free unity scripts / library's / plugins and extensions
Stars: ✭ 3,640 (+3037.93%)
Mutual labels:  unity-scripts, unity-asset
Unity Ui Examples
📚 A collection of UI examples for Unity.
Stars: ✭ 152 (+31.03%)
Mutual labels:  unity-scripts, unity-asset
unity-firebase-realtime-database
Unity Firebase Realtime Database REST
Stars: ✭ 24 (-79.31%)
Mutual labels:  unity-scripts, unity-asset
UnityDebug
A wrapper script for Unity debug calls to use conditional attributes in order to avoid debug code being compiled into release builds.
Stars: ✭ 29 (-75%)
Mutual labels:  unity-scripts, unity-asset
Unity-2017.2-and-Vuforia-6.5---Camera-Auto-Focus
Unity 2017.2 and Vuforia 6.5 Augmented Reality (AR) Camera Auto Focus
Stars: ✭ 17 (-85.34%)
Mutual labels:  unity-scripts, unity-asset
save-file
Save any data to file in browser or node
Stars: ✭ 40 (-65.52%)
Mutual labels:  filesystem, save

Save System for Unity

TODO

  • Assets References
  • AOT support
  • Upload MessagePack version to separate branch? MessagePack version has better performance and less file size (WIP)

Features

  • Can save pretty much everything (Vector, Quaternion, Array, List, Class, Struct, etc)
  • Can save assets references
  • As easy to use as PlayerPrefs
  • Fast in terms of performance. Even simple int saving way more faster than PlayerPrefs.SetInt(). Performance test at the end of README
  • Save files are encrypted
  • Multiple profiles

How to Install

Git Installation (Best way to get latest version)

If you have Git on your computer, you can open Package Manager indside Unity, select "Add package from Git url...", and paste link https://github.com/IntoTheDev/Save-System-for-Unity.git

or

Open the manifest.json file of your Unity project. Add "com.intothedev.savesystem": "https://github.com/IntoTheDev/Save-System-for-Unity.git"

Manual Installation (Version can be outdated)

Download latest package from the Release section. Import SaveSystem.unitypackage to your Unity Project

Usage

Saving

float health = 100f;
DataSerializer.Save("SaveKeyHere", health);

Loading

float health = DataSerializer.Load<float>("SaveKeyHere");

Check for key

if (DataSerializer.HasKey("SaveKeyHere"))
	float health = DataSerializer.Load<float>("SaveKeyHere");
	
// OR

float health;

if (DataSerializer.TryLoad("SaveKeyHere", out float value))
	health = value;

Delete key

DataSerializer.DeleteKey("SaveKeyHere");

Delete all save file data

DataSerializer.DeleteAll();

Change profile. Old profile will be saved and new one is loaded.

DataSerializer.ChangeProfile(profileIndex: 1);

Complex example

using System.Collections.Generic;
using ToolBox.Serialization;
using UnityEngine;

public class Player : MonoBehaviour
{
	[SerializeField] private float _health = 0f;
	[SerializeField] private List<Item> _inventory = new List<Item>();

	private const string SAVE_KEY = "PlayerSaveData";

	private void Awake()
	{
		DataSerializer.FileSaving += FileSaving;

		if (DataSerializer.TryLoad<SaveData>(SAVE_KEY, out var loadedData))
		{
			_health = loadedData.Health;
			transform.position = loadedData.Position;
			_inventory = loadedData.Inventory;
		}
	}

	// This method will be called before application quits
	private void FileSaving()
	{
		DataSerializer.Save(SAVE_KEY, new SaveData(_health, transform.position, _inventory));
	}
}

// If you want to make scriptable object or any other asset saveable then you need to add that asset to Assets Container. 
// See guide below
[CreateAssetMenu]
public class Item : ScriptableObject
{
	[SerializeField] private string _name = string.Empty;
	[SerializeField] private int _cost = 100;
}

public struct SaveData
{
    [SerializeField] private float _health;
    [SerializeField] private Vector3 _position;
    [SerializeField] private List<Item> _inventory;

    public float Health => _health;
    public Vector3 Position => _position;
    public List<Item> Inventory => _inventory;
    
    public SaveData(float health, Vector3 position, List<Item> inventory)
    {
        _health = health;
        _position = position;
        _inventory = inventory;
    }
}

How to make asset saveable

  1. Open Assets Container window. Window/Assets Container. Window looks like this:

image

  1. Select path where your assets stored. If you already have path field then press the Select Path button or Add Path if not. In my case path is Assets/ScriptableObjects/Items.

  2. Press the Load assets at paths button.

  3. That's all!

image

AOT platforms

You need to create a simple C# class and implement ITypeProvider interface. Then you need to add types (except primitive ones) that will be saved in your game.

Example for case above

using System;
using System.Collections.Generic;
using ToolBox.Serialization;
using UnityEngine;

public sealed class TestProvider : ITypeProvider
{
    public Type[] GetTypes()
    {
        return new Type[]
        {
            typeof(SaveData),
            typeof(Vector3),
            typeof(List<Item>)
        };
    }
}

Performance test

PlayerPrefs result: 329 milliseconds

Code:

using Sirenix.OdinInspector;
using System.Diagnostics;
using UnityEngine;

public class Tester : MonoBehaviour
{
	[SerializeField] private int _number = 0;

	[Button]
	private void Test()
	{
		Stopwatch stopwatch = new Stopwatch();
		stopwatch.Start();

		for (int i = 0; i < 10000; i++)
		{
			PlayerPrefs.SetInt("SAVE", _number);
			_number = PlayerPrefs.GetInt("SAVE");
		}

		stopwatch.Stop();
		print(stopwatch.Elapsed.TotalMilliseconds);
	}
}

DataSerializer result: 18 milliseconds

Code:

using Sirenix.OdinInspector;
using System.Diagnostics;
using ToolBox.Serialization;
using UnityEngine;

public class Tester : MonoBehaviour
{
	[SerializeField] private int _number = 0;

	[Button]
	private void Test()
	{
		Stopwatch stopwatch = new Stopwatch();
		stopwatch.Start();

		for (int i = 0; i < 10000; i++)
		{
			DataSerializer.Save("SAVE", _number);
			_number = DataSerializer.Load<int>("SAVE");
		}

		stopwatch.Stop();
		print(stopwatch.Elapsed.TotalMilliseconds);
	}
}

License

DataSerializer folder is licensed under the MIT License, see LICENSE for more information.

OdinSerializer folder is licensed under the Apache-2.0 License, see LICENSE for more information. Odin Serializer belongs to Team Sirenix

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].