Saving an Loading a List<Type>

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
User avatar
Joel
Moodkie Staff
Posts: 4810
Joined: Wed Nov 07, 2012 10:32 pm

Saving an Loading a List<Type>

Post by Joel »

Saving and Loading a List<Type>

Notes
  • Easy Save can only save lists which contain objects which are on the Supported Types list.
  • Easy Save cannot save Lists containing other collection types. For example: List<List<Type>>
Saving

To save a List, we use the ES2.Save(data, path) method, where:
  • data is the List that we wish to save.
  • path is a string that we use to identify this piece of data, among other things.
Example: Saving a List<string>
// Create the List that we want to save.
List<string> myStrings = new List<string>();
myStrings.Add("myString");

// Save the List. We'll use "mySavedString" to uniquely identify it.
ES2.Save(myStrings, "mySavedStrings");

Loading

To load a List<Type>, we use ES2.LoadList<Type>(path), where:
  • Type is the type of data contained in the List.
  • path is the path we specified when saving the List.
We also use ES2.Exists(path) to check that there is data to load.

Example: Loading a List<string>
List<string> myStrings;

// If there's a List to load, load it.
if(ES2.Exists("mySavedStrings"))
    myStrings = ES2.LoadList<string>("mySavedStrings");
When should I save and load data?

This depends on your project. However, it's usually best to Load data in Start(), and Save data in OnDestroy(), which is usually called whenever the Application is quit or the scene is changed.
Locked