Skip to content

DerKekser/unity-save-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unity - Save System

Save System is a simple save system for Unity. It allows you to save and load scene objects and their components.

Contents

Saving and Loading

You can save and load the current scene by using the SaveLoadManager class.

using Kekser.SaveSystem;

// ...

SaveLoadManager.Save(path);
SaveLoadManager.Load(path);

Using the Savable Component

You can save and load a scene object by adding the Savable component to it. You can use it on any scene object, but it is recommended to use it on Prefabs.

This package contains a SavableTransform and a SavableRigidbody component. You can use them to save and load the transform and the rigidbody of a scene object.

Savable Component

Prefab Registry

To be able to save and load prefabs, you have to register them in the PrefabRegistry. You can create and update the prefab registry by clicking on Tools/Save System/Update Prefabs.

This is a manual process, and needs to be done every time you add a new prefab to your project.

Prefab Registry

Create your own Savable Component

You can create your own savable component by using the Savable, Save or Load attribute.\

Fields

using Kekser.SaveSystem;

[Savable]
private int _score = 100;

Methods

using Kekser.SaveSystem;

private int _score = 100;

[Save]
private void Save(DataObject data)
{
    data.Add("Score", new DataElement(_score));
}

[Load]
private void Load(DataObject data)
{
    _score = data.Get<DataElement>("Score").ToObject<int>();
}

These attributes are also usable on static fields and methods.

Data Types

DataObject

The DataObject class is a dictionary that contains other DataObject, DataArray and DataElement objects.

DataArray

The DataArray class is a list that contains other DataObject, DataArray and DataElement objects.

DataElement

The DataElement class is a wrapper for any supported types.

Supported Types

  • byte[]
  • int
  • float
  • bool
  • string
  • Vector2
  • Vector3
  • Vector4
  • Quaternion
  • Color
  • Type
  • Guid
  • IList
  • IDictionary
  • Array
  • Enum
  • Class
  • Struct
  • GameObject

Install via git URL

You can add this package to your project by adding this git URL to the package manager:

https://github.com/DerKekser/unity-save-system.git?path=Assets/Kekser/SaveSystem

Package Manager

License

This library is under the MIT License.