Supported Types
Custom Types
Most custom types can be supported by creating an ES2Type for it, either automatically using Manage Types… or manually using a template.
For information on how to do this, please see the Adding Support for Other Types guide.
Primitive Types
- int
- float
- string
- byte
- bool
- char
- long
- short
- uint
- ulong
- ushort
- Enum
- DateTime
Collections
Note: Saving collections containing collections is not directly supported, but can be achieved with the ‘Saving Nested Collections’ guide.
- Array [ ]
- 2D Array [,]
- 3D Array [,,]
- Dictionary<TKey, TValue>
- List<T>
- Queue<T>
- HashSet<T>
- Stack<T>
Unity Types
Click a type to see what variables it saves.
Vector2
- x
- y
- x
- y
- z
- x
- y
- z
- w
- x
- y
- z
- w
- r
- g
- b
- a
- r
- g
- b
- a
- pixels
- filterMode
- anisoLevel
- wrapMode
- mipMapBias
- texture
- rect
- bounds
- textureRect
- name
Note: Textures are saved by value, not by reference.
- Textures
- shader
- textureOffset
- textureScale
Note: Meshes are saved by value, not by reference.
- submeshes
- vertices
- triangles
- normals
- uv
- uv2
- tangents
- bindposes
- boneWeights
- colors32
Note: AudioClips are saved by value, not by reference.
Note 2: Data is saved in a raw format so this may not be suitable for long AudioClips.
- name
- samples
- channels
- frequency
- x
- y
- width
- height
- center
- size
- columns
- boneIndex0
- boneIndex1
- boneIndex2
- boneIndex3
- weight0
- weight1
- weight2
- weight3
Components
Click a type to see what variables it saves.
TransformNote: Components are saved by value, not by reference.
- position
- rotation
- localScale
- tag
Note: Components are saved by value, not by reference.
- center
- radius
- isTrigger
Note: Components are saved by value, not by reference.
- center
- size
- isTrigger
Note: Components are saved by value, not by reference.
- center
- radius
- height
- direction
- isTrigger
Note: Components are saved by value, not by reference.
- sharedMesh
- convex
- smoothSphereCollisions
- isTrigger
Saving Nested Collections
It’s not possible to save Collections which contain other collections due to limitations in C# / UnityScript.
However, an easy workaround is to create a wrapper class which contains your inner collection, and then add that as a supported type. You can then save a Collection of these wrapper classes.
For example, a wrapper class for an int array might look like this:
1 2 3 4 5 6 7 8 9 10 11 |
public class ArrayWrapper { public int[] array; public static ArrayWrapper Create(int[] array) { ArrayWrapper wrapper = new ArrayWrapper(); wrapper.array = array; return wrapper; } } |
We can then use this to store a List of arrays as follows:
1 2 3 4 5 6 7 8 9 10 11 |
List<ArrayWrapper> intArrayList = new List<ArrayWrapper>(); // Add some arrays to our List using the ArrayWrapper to wrap them. intArrayList.Add( ArrayWrapper.Create( new int[]{1, 2, 3} ) ); intArrayList.Add( ArrayWrapper.Create( new int[]{4, 5, 6, 7, 8} ) ); intArrayList.Add( ArrayWrapper.Create( new int[]{9, 10} ) ); // Save our List. ES2.Save(intArraylist, "myFile.txt?tag=intArrayList"); // Load our List. intArrayList = ES2.LoadList<ArrayWrapper>("myFile.txt?tag=intArrayList"); |
Saving GameObjects
We’ve created an ES2Type for saving and loading GameObjects, but is also provided here as an example.
It saves a GameObject and it’s supported Components. Note that this will not save the children of the GameObject.
After creating the ES2Type file below, you will need to refresh the type list by going to Assets > Easy Save 2 > Manage Types and pressing the Refresh ES2Init button.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
using System.Collections.Generic; using UnityEngine; public sealed class ES2_GameObject : ES2Type { public ES2_GameObject() : base(typeof(GameObject)) { } public override void Write(object data, ES2Writer writer) { GameObject go = (GameObject)data; // Get the Components of the GameObject that you want to save and save them. var components = go.GetComponents(typeof(Component)); var supportedComponents = new List<Component>(); // Get the supported Components and put them in a List. foreach (var component in components) if (ES2TypeManager.GetES2Type(component.GetType()) != null) supportedComponents.Add(component); // Write how many Components we're saving so we know when we're loading. writer.Write(supportedComponents.Count); // Save each Component individually. foreach (var component in supportedComponents) { var es2Type = ES2TypeManager.GetES2Type(component.GetType()); writer.Write(es2Type.hash); es2Type.Write(component, writer); } } public override void Read(ES2Reader reader, object obj) { GameObject go = (GameObject)obj; // How many components do we need to load? int componentCount = reader.Read<int>(); for (int i = 0; i < componentCount; i++) { // Get the ES2Type using the hash stored before the component. var es2Type = ES2TypeManager.GetES2Type(reader.Read<int>()); // Get Component from GameObject, or add it if it doesn't have one. Component c = go.GetComponent (es2Type.type); if(c == null) c = go.AddComponent(es2Type.type); // Use the ES2Type to read. es2Type.Read(reader, c); } } public override object Read(ES2Reader reader) { GameObject go = new GameObject(); Read(reader, go); return go; } } |