SaveGame.Save

Description

Saves the value in the specified identifier.

Parameters

Name Type Description Required
identifier string The identifier required
value object The value to save required
settings SaveGameSettings The optional settings optional

Examples

Saving Simple Data

SaveGame.Save ( "simple.txt", "Simple Data" );

Saving Array

string[] names = new string[] { "John", "James", "Kyle" };
SaveGame.Save ( "names.txt", names );

Saving to Folder

SaveGame.Save ( "myFolder/myFile.txt", "Sample Text" );

Saving Inventory

The Inventory class:

public class Inventory {

    public Slot[] slots;

    public Inventory () {
        slots = new Slot[5];
    }

}

The Slot class:

public class Slot {

    public Item item;
    public int amount;

}

The Item class:

public class Item {

    public string name;
    public string description;
    public string imagePath;

}

Now, let us save the whole inventory:

// Creating a simple inventory
Inventory inventory = new Inventory ();
Slot slot = new Slot ();
Item item = new Item ();

item.name = "Sword";
item.description = "The sword for livings.";
item.imagePath = "Textures/sword";

slot.item = item;
slot.amount = 2;

inventory.slots[0] = slot;

// Save the inventory
SaveGame.Save ( "inventory", inventory );

// Load the inventory
inventory = SaveGame.Load<Inventory> ( "inventory" );