Inventory
Read more about the Inventory system in Hiro here.
Initializing the inventory system #
The inventory system relies on the Nakama System and an ILogger, both must be passed in as dependencies via the constructor.
| |
Subscribing to changes in the inventory system #
You can listen for changes in the inventory system so that you can respond appropriately, such as updating the UI, by implementing the IObserver pattern, or use the SystemObserver<T> type which handles it for you.
| |
Refreshing the inventory system #
To ensure the inventory system has the latest information from Nakama you can refresh it.
| |
Listing the available items #
You can list the available items in the inventory system.
| |
You can optionally retrieve a filtered list of items by category.
| |
Listing the user’s inventory #
You can list a user’s inventory.
| |
Granting inventory items #
Grant one or more inventory items to the player.
| |
Removing inventory items #
To remove items from a user’s inventory, without consuming them, use a negative grant value.
| |
Deleting item instances #
Delete a specific item instance by its instance ID, rather than reducing its stacked count. Use this for non-stackable items, or items whose instance carries state that a count can’t represent.
| |
See Removing items for when to choose this over a negative grant.
Consuming items #
You can consume items or item instances 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).
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. | |
Updating item properties #
You can update the properties on an item instance.
| |
