In this section you will learn how to manage the inventory of the local user.
Loading Inventory
To retrieve the list of items in the inventory of a user you need to call the Inventory.Load:
Inventory.Load( "123", (Inventory[] items, string error) => {
if (success)
Debug.Log("Success: " + items.Length);
else
Debug.Log("Failed: " + error);
});
Adding and Editing Items
To add a new item in the inventory of the local user you need to create a new Inventory instance, set name, quantity and customData and then call Update:
Inventory newItem = new Inventory();
newItem.name = "My item";
newItem.quantity = 1;
newItem.customData["Durability"] = 100;
newItem.Update( (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});
myItem.quantity--;
myItem.Update( (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});
Removing Items
To remove an item from the inventory of the local user you need to call Inventory.Delete:
Inventory.Delete(123, (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});
myItem.Delete( (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});