Inventory #

Read more about the Inventory system in Hiro here.

Refreshing the inventory system #

You can refresh the inventory system’s data.

1
await inventorySystem.RefreshAsync();

Listing the available items #

You can list the available items in the inventory system.

1
2
3
4
5
6
7
8
var result = await inventorySystem.GetItemCodexAsync();

foreach (var itemKvp in result.Items)
{
    var id = itemKvp.Key;
    var item = itemKvp.Value;
    Debug.Log($"Item {id}: {item.Name} - {item.Description}");
}

You can optionally retrieve a filtered list of items by category.

1
2
var category = "<category1>";
var result = await inventorySystem.GetItemCodexAsync(category)

Listing the user’s inventory #

You can list a user’s inventory.

1
2
3
4
5
6
foreach (var itemKvp in inventorySystem.Items)
{
    var id = itemKvp.Key;
    var item = itemKvp.Value;
    Debug.Log($"Item {id}: {item.Name} - {item.Description}");
}

Granting inventory items #

You can grant inventory items to the user.

1
2
3
4
5
6
7
var items = new Dictionary<string, long>
{
    { "<itemId1>", 1 },
    { "<itemId2>", 10 }
};

await inventorySystem.GrantItemsAsync(items);

Consuming items #

You can consume items for a user that have the consumable flag. You can specify whether or not the user is allowed to overconsume (use more than they have).

Setting overconsume to true can be useful when handling multiple device scenarios. This allows consumption of the item, even if the local device’s resource data is out of sync. However, once the item reaches zero, further consumption is prevented, irrespective of the overconsume setting. This provides developers flexibility in managing inventory inconsistencies across devices.
1
2
3
4
5
6
7
8
9
var toConsume = new Dictionary<string, long>
{
    {"<consumableId1>", 2},
    {"<consumableId2>", 1}
};

var overconsume = false;

await inventorySystem.ConsumeItemsAsync(toConsume, overconsume);

Updating item properties #

You can update the properties on an item instance.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
var updates = new Dictionary<string, UpdateInventoryItemProperties>();
updates.Add("itemId1", new UpdateInventoryItemProperties
{
  StringProperties = new Dictionary<string, string> 
  {
    { "crafted_by", "username" }
  },
  NumericProperties = new Dictionary<string, double>
  {
    { "rank",  5 }
  }
});

await inventorySystem.UpdateItemsAsync(updates);