Component Save System
UnityUnity Asset Store
Knowledge & experience
- Providing customer service & support for plugin. 8 updates published since release.
- Serialization methodologies & implementations (JSON, Binary, SQLite)
- Acquired knowledge of Unity execution orders & object destruction events
- Developing plugin that is generalized to work for a lot of projects.
- Usage of Path, Directory and File classes.
- 30 five star reviews.
About the project
Component Save System is a high-rated saving plugin for the Unity Engine.
The save system came to existence when developing RPG Farming Kit, a template for people who wanted to create games similar to Harvest Moon and Stardew Valley.
Currently available on the Unity Asset Store as a paid plugin. Initially the plugin was released as a open source project. Eventually developers asked me to make it a paid plugin because they wanted more consistent maintenance.
Main selling point of the plugin is to make it easy to save individual components. This was done by adding the ISaveable interface to said components, and placing a component at the root of a game object that scans the entire object during editor-time for said interface.
Code Samples
Example of how you would save a component
using Lowscope.Saving;
using UnityEngine;
namespace Lowscope.Saving.Components
{
public class SaveVisibility : MonoBehaviour, ISaveable
{
private bool isEnabled;
private void OnEnable() => isEnabled = true;
private void OnDisable()
{
// Ensure that it doesn't get toggled during scene load/unload
if (SaveMaster.DeactivatedObjectExplicitly(gameObject))
isEnabled = false;
}
public void OnLoad(string data)
{
isEnabled = data == "1";
gameObject.SetActive(isEnabled);
}
public string OnSave() => isEnabled ? "1" : "0";
public bool OnSaveCondition() => true;
}
}
Example of AB file saving.
// Created by Alex Meesters
// www.low-scope.com, www.alexmeesters.nl
// Licenced under the MIT Licence. https://en.wikipedia.org/wiki/MIT_License
using System;
using System.IO;
using System.Text;
public static class BackupABExample
{
private const string BackupExtension = ".b";
public static string SaveBackupPath(string path)
{
string altPath = GetAlternativeFilePath(path, BackupExtension);
return GetOldestFilePath(path, altPath);
}
public static string LoadBackupPath(string path)
{
string altPath = GetAlternativeFilePath(path, BackupExtension);
return GetNewestFilePath(path, altPath);
}
private static string GetOldestFilePath(string pathOne, string pathTwo)
{
bool pathOneExists = File.Exists(pathOne);
bool pathTwoExists = File.Exists(pathTwo);
if (!pathOneExists)
return pathOne;
if (!pathTwoExists)
return pathTwo;
DateTime pathOneWriteTime = File.GetLastWriteTime(pathOne);
DateTime pathTwoWriteTime = File.GetLastWriteTime(pathTwo);
return pathOneWriteTime < pathTwoWriteTime ? pathOne : pathTwo;
}
private static string GetNewestFilePath(string pathOne, string pathTwo)
{
bool pathOneExists = File.Exists(pathOne);
bool pathTwoExists = File.Exists(pathTwo);
if (!pathOneExists && !pathTwoExists)
return "";
if (pathOneExists && !pathTwoExists)
return pathOne;
if (!pathOneExists)
return pathTwo;
DateTime pathOneWriteTime = File.GetLastWriteTime(pathOne);
DateTime pathTwoWriteTime = File.GetLastWriteTime(pathTwo);
return pathOneWriteTime > pathTwoWriteTime ? pathOne : pathTwo;
}
private static string GetAlternativeFilePath(string path, string extensionName)
{
return new StringBuilder()
.Append(path)
.Append(extensionName)
.ToString();
}
}