Saving an Loading a List<Type>
Posted: Fri Oct 18, 2013 3:39 pm
Saving and Loading a List<Type>
Notes
To save a List, we use the ES2.Save(data, path) method, where:
Loading
To load a List<Type>, we use ES2.LoadList<Type>(path), where:
Example: Loading a List<string>
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.
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>>
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.
// 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.
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.