Loading

How to load data from SaveStates.

Single

The main method to load data is the generic GetData method. Replace T with the type of the data you're trying to retrieve.

// Where T is the data type
saveState.GetData<T>("DataID").OnComplete(result =>
{
    Debug.Log(result);
});

This method returns a Save Operation (result type: T).

Multiple (Single Type)

You can also retrieve a list of data of the same type:

// Where T is the data type
saveState.GetData<T>("DataID1", "DataID2", "DataID3").OnComplete(result =>
{
    Debug.Log(result["DataID1"]);
    Debug.Log(result["DataID2"]);
    Debug.Log(result["DataID3"]);
});

This method returns a Save Operation (result type: Dictionary<string, T>).

Multiple (Multi-Type)

It's also possible to retrieve a list of data of unique types. This can be done by providing a value tuple where the first item is the data ID and the second is the data type.

saveState.GetData(("DataID1", typeof(float)), ("DataID2", typeof(int)), ("DataID3", typeof(string))).OnComplete(result =>
{
    Debug.Log(result["DataID1"]);
    Debug.Log(result["DataID2"]);
    Debug.Log(result["DataID3"]);
});

This method returns a Save Operation (result type: Dictionary<string, dynamic>).

Special Methods

ESave features special methods to retrieve data for some otherwise unsavable Unity types.

Vector2

saveState.GetVector2("DataID").OnComplete(v2 => Debug.Log(v2));

Vector3

saveState.GetVector3("DataID").OnComplete(v3 => Debug.Log(v3));

Vector4

saveState.GetVector4("DataID").OnComplete(v4 => Debug.Log(v4));

Quaternion

saveState.GetQuaternion("DataID").OnComplete(q => Debug.Log(q));

Color

saveState.GetColor("DataID").OnComplete(c => Debug.Log(c));

Transform

// Returns a SavableTransform
saveState.GetTransform("DataID").OnComplete(st =>
{
    // Set position and rotation
    transform.SetPositionAndRotation(st.Position, st.Rotation);
});

RectTransform

saveState.GetRectTransform("DataID").OnComplete(srt =>
{
    // Set anchored position, size, and rotation
    var rectTransform = transform as RectTransform;
    rectTransform.anchoredPosition = srt.AnchoredPosition;
    rectTransform.sizeDelta = srt.SizeDelta;
    rectTransform.rotation = srt.Rotation;
});

Last updated