Automatically adding support for a Type
You can attempt to automatically add support for a Type by going to the Assets menu and selecting Easy Save 2 > Manage Types. Then find the type you wish to add support for in the type list, select the properties of the type which you would like to save, and then press Add Type.
Easy Save can add support for types which provide a parameterless constructor, and can support properties which are:
- Allows reading and writing
- Is currently supported by Easy Save
For other types, you may be able to manually add support (see below).
Manually adding support for a Type
If support cannot be automatically added for a Type, you may be able to manually add support for it.
The easiest way to do this is to create an ES2Type Template by going to to the Assets menu and selecting Easy Save 2 > Manage Types, finding your type in the type list and then pressing Add Type. Once you have done this, press Edit Type to open up the Type Template in your default editor so that you can edit it.
You will then need to change the Write and Read methods to include ES2Writer and ES2Reader calls.
Adding to the Write method
The Write method needs to write the data you want to save from the data variable into the ES2Writer. You can do this by using writer.Write() calls.
public override void Write(object obj, ES2Writer writer)
MyType data = (MyType)obj;
// Add your writer.Write calls here.
writer.Write( data.height );
writer.Write( data.width );
writer.Write( data.name );
Note that the type of the data you are writing must also be a type supported by Easy Save.
Adding to the Read method
The Read method needs to read the data in the same order that it was written in the Write method using reader.Read<T>() calls, and then use that data to construct your loaded object and return it.
public override object Read(ES2Reader reader)
float height = reader.Read<float>();
int width = reader.Read<int>();
string name = reader.Read<string>();
MyType type = new MyType(height, width, name);