Introduction to Adapters
Some Unity components are very complicated for SaveIsEasy to save them and load them correctly, so the asset has adapters, it allows you to save more complicated components, such as animations, it is designed so that the user can create adapters according to their needs.
You can find the adapters in the folder: "\Assets\Save is easy\Adapters"
We will be adding new adapters as they are requested, but you have the freedom to modify them or create some more for specific things.
Example of how to create an adapter
In this example we will show how to create an adapter that stores the Transform position.
For an adapter to work properly you need some things in the class:
- AdapterAttribute: The adapter needs this attribute at the beginning of its class to tell the asset that the class is an adapter. Information on the Arguments.
- ISaveIsEasyEvents: So that the adapted can receive events needs to have this interface, More info.
- OnLoad: This function is required by the ISaveIsEasyEvents interface, It acts as an event when the asset is about to save this GameObject calls this function.
- OnSave: This function is required by the ISaveIsEasyEvents interface, it acts as an event when the asset ends loading all the information of this component calls this function.
- AlwaysSave: You can use this attribute so that you do not have to select the attribute to be saved in the "SaveIsEasyComponent", More info.
using SaveIsEasy;
using SaveIsEasy.Adapter;
using UnityEngine;
[Adapter(typeof(Transform), true)]
public class PositionAdapter : MonoBehaviour, ISaveIsEasyEvents {
[AlwaysSave]
private Vector3 pos;
public void OnLoad() {
transform.position = pos;
}
public void OnSave() {
pos = transform.position;
}
}