Inventory
Integration Guide
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.
/// <summary>
/// Base inventory structure
/// </summary>
[System.Serializable]
public sealed class VirtualItemInventoryData
{
/// <summary>
/// Unique id of the inventory item
/// </summary>
public string id;
/// <summary>
/// The Virtual Item id for this inventory item
/// </summary>
public string virtualItemId;
/// <summary>
/// List of application ids where this item is used
/// </summary>
public List<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>
public List<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>
public int 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>
public VirtualItemUpgrade[] 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>
public List<Properties> properties;
}
The following method gets all inventory items for the currently logged in user:
using System.Collections.Generic;
using RGN.Modules.Inventory;
namespace SomeNamespace
{
internal sealed class GetInventoryItems
{
public async void GetInventoryAsync()
{
List<InventoryItemData> inventoryItems =
await InventoryModule.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.
The following method will get the inventory items with the Virtual Item data included:
using System.Collections.Generic;
using RGN.Modules.Inventory;
namespace SomeNamespace
{
internal sealed class GetInventoryItemsWithVirtualItemsData
{
public async void GetInventoryWithVirtualItemDataAsync()
{
List<InventoryItemData> inventoryItems =
await InventoryModule.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.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:using RGN.Modules.Inventory;
namespace SomeNamespace
{
internal sealed class UpgradeInventoryItem
{
public async void UpgradeInventoryItemAsync()
{
string inventoryItemId = "some_id_for_item_in_inventory";
var result = await InventoryModule.I.UpgradeAsync(inventoryItemId, 42);
}
}
}
But you can also have multiple upgrade ids for the same item:
using RGN.Modules.Inventory;
namespace SomeNamespace
{
internal sealed class CustomUpgradeIdInventoryItem
{
public async void UpgradeInventoryItemAsync()
{
string inventoryItemId = "some_id_for_item_in_inventory";
await InventoryModule.I.UpgradeAsync(inventoryItemId, 13, "damage");
await InventoryModule.I.UpgradeAsync(inventoryItemId, 27, "reload");
}
}
}
It is only possible to upgrade non-stackable virtual items. If the virtual item is stackable, then the upgrade method will throw an exception.
Last modified 13d ago