After the user purchases a Virtual Item, it is added to the user's Inventory. It is possible also to add a virtual item to the user's inventory without going through the purchase process.
Inventory Item structure
/// <summary>/// Base inventory structure/// </summary>[System.Serializable]publicsealedclassVirtualItemInventoryData{ /// <summary> /// Unique id of the inventory item /// </summary>publicstring id; /// <summary> /// The Virtual Item id for this inventory item /// </summary>publicstring virtualItemId; /// <summary> /// List of application ids where this item is used /// </summary>publicList<string> appIds; /// <summary> /// List of tags to filter the offers /// You can place multiple inventory items into one category tag /// For example in a shooter game: "guns", "rifles" /// Later in the UI you can get only inventory items for specific tag /// </summary>publicList<string> tags; /// <summary> /// How many items the user have in inventory /// If the Virtual Item is non stackable, then this value should be /// always one /// For stackable Virtual Items it represents the count of Virtual Items /// in user inventory. /// </summary>publicint quantity; /// <summary> /// The upgrades for non stackable virtual item /// The user can upgrade the Virtual Items he owns /// The upgrades can change some of the properties of Virtual Items /// It is possible to have multiple upgrades with different names and values /// for one item. /// </summary>publicVirtualItemUpgrade[] itemUpgrades; /// <summary> /// List of inventory item custom properties. It is used to store /// game specific properties in json format. /// For example: you can attach some properties like /// "additiona_description", "in_app_products", "display_animation" for this /// inventory item /// </summary>publicList<Properties> properties;}
Retrieving items from inventory:
The following method gets all inventory items for the currently logged in user:
usingSystem.Collections.Generic;usingRGN.Modules.Inventory;namespaceSomeNamespace{internalsealedclassGetInventoryItems {publicasyncvoidGetInventoryAsync() {List<InventoryItemData> inventoryItems =awaitInventoryModule.I.GetAllForCurrentAppAsync();for (int i =0; i <inventoryItems.Count; i++) {var item =inventoryItems[i];UnityEngine.Debug.Log(item.virtualItemId); } } }}
The method above retrieves a list of Virtual Item IDs that the user has purchased. To get the virtual items data, you can use the VirtualItemsModule.I.GetVirtualItemsByIdsAsync() method.
Retrieving inventory items with Virtual Items data:
The following method will get the inventory items with the Virtual Item data included:
usingSystem.Collections.Generic;usingRGN.Modules.Inventory;namespaceSomeNamespace{internalsealedclassGetInventoryItemsWithVirtualItemsData {publicasyncvoidGetInventoryWithVirtualItemDataAsync() {List<InventoryItemData> inventoryItems =awaitInventoryModule.I.GetWithVirtualItemsDataForCurrentAppAsync();for (int i =0; i <inventoryItems.Count; i++) {var item =inventoryItems[i];UnityEngine.Debug.Log(item.GetVirtualItem().name); } } }}
In the code above you can see that the inventory item contains now a non-null Item property. It is the virtual item data.
Upgrade inventory item:
This can be used to add a booster for any purchased non-stackable virtual item.
By default, if you don't specify the upgradeId the "default" is used:
usingRGN.Modules.Inventory;namespaceSomeNamespace{internalsealedclassUpgradeInventoryItem {publicasyncvoidUpgradeInventoryItemAsync() {string inventoryItemId ="some_id_for_item_in_inventory";var result =awaitInventoryModule.I.UpgradeAsync(inventoryItemId,42); } }}
But you can also have multiple upgrade ids for the same item: