Combu  2.1.14
Unity API Documentation
Managing Inventory

Table of Contents

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:

// Load the inventory of user ID '123'
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:

// Add a new item
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);
});
// Edit an item previously loaded
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:

// Remove by inventory ID '123'
Inventory.Delete(123, (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});
// Remove by Inventory object
myItem.Delete( (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});