API

CBSInventoryModule.GetInventory - Get inventory items list of current profile.

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        Inventory.GetInventory(OnGetInventory);
    }

    private void OnGetInventory(CBSGetInventoryResult result)
    {
        if (result.IsSuccess)
        {
            var profileID = result.TargetID;
            var items = result.AllItems;
            var lootboxes = result.Lootboxes;
            var equippedItems = result.EquippedItems;
            var nonEquippedItems = result.NonEquippedItems;
            var equippableItems = result.EquippableItems;
            var tradableItems = result.TradableItems;
            var consumableItems = result.ConsumableItems;
            var recipeItems = result.RecipeItems;
            var isInTradingItems = result.IsInTradingItems;
        }
    }
}

CBSInventoryModule.GetInventoryByCategory - Get inventory items list of current profile by specific category.

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        var category = "your category";
        Inventory.GetInventoryByCategory(category, OnGetInventory);
    }

    private void OnGetInventory(CBSGetInventoryResult result)
    {
        if (result.IsSuccess)
        {
            var profileID = result.TargetID;
            var items = result.AllItems;
            var lootboxes = result.Lootboxes;
            var equippedItems = result.EquippedItems;
            var nonEquippedItems = result.NonEquippedItems;
            var equippableItems = result.EquippableItems;
            var tradableItems = result.TradableItems;
            var consumableItems = result.ConsumableItems;
            var recipeItems = result.RecipeItems;
            var isInTradingItems = result.IsInTradingItems;
        }
    }
}

CBSInventoryModule.GetProfileInventoryByProfileID - Get inventory items list by profile id

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        var profileID = "some profile ID";
        Inventory.GetProfileInventoryByProfileID(profileID, OnGetInventory);
    }

    private void OnGetInventory(CBSGetInventoryResult result)
    {
        if (result.IsSuccess)
        {
            var profileID = result.TargetID;
            var items = result.AllItems;
            var lootboxes = result.Lootboxes;
            var equippedItems = result.EquippedItems;
            var nonEquippedItems = result.NonEquippedItems;
            var equippableItems = result.EquippableItems;
            var tradableItems = result.TradableItems;
            var consumableItems = result.ConsumableItems;
            var recipeItems = result.RecipeItems;
            var isInTradingItems = result.IsInTradingItems;
        }
    }
}

CBSInventoryModule.GetInventoryByCategoryByProfileID - Get inventory items list by specific category by profile id.

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        var profileID = "some profile ID";
        var category = "your category";
        Inventory.GetInventoryByCategoryByProfileID(profileID, category, OnGetInventory);
    }

    private void OnGetInventory(CBSGetInventoryResult result)
    {
        if (result.IsSuccess)
        {
            var profileID = result.TargetID;
            var items = result.AllItems;
            var lootboxes = result.Lootboxes;
            var equippedItems = result.EquippedItems;
            var nonEquippedItems = result.NonEquippedItems;
            var equippableItems = result.EquippableItems;
            var tradableItems = result.TradableItems;
            var consumableItems = result.ConsumableItems;
            var recipeItems = result.RecipeItems;
            var isInTradingItems = result.IsInTradingItems;
        }
    }
}

CBSInventoryModule.GetInventoryFromCache - Get last cached inventory.

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        Inventory.GetInventoryFromCache(OnGetInventory);
    }

    private void OnGetInventory(CBSGetInventoryResult result)
    {
        if (result.IsSuccess)
        {
            var profileID = result.TargetID;
            var items = result.AllItems;
            var lootboxes = result.Lootboxes;
            var equippedItems = result.EquippedItems;
            var nonEquippedItems = result.NonEquippedItems;
            var equippableItems = result.EquippableItems;
            var tradableItems = result.TradableItems;
            var consumableItems = result.ConsumableItems;
            var recipeItems = result.RecipeItems;
            var isInTradingItems = result.IsInTradingItems;
        }
    }
}

CBSInventoryModule.GetItemByInstanceID - Get full information of inventory item by instance id.

using CBS;
using CBS.Example;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        var instanceID = "item instance id";
        Inventory.GetItemByInstanceID(instanceID, OnGetInventory);
    }

    private void OnGetInventory(CBSGetInventoryItemResult result)
    {
        if (result.IsSuccess)
        {
            var inventoryItem = result.InventoryItem;
            var instanceID = inventoryItem.InstanceID;
            var itemID = inventoryItem.ItemID;
            var category = inventoryItem.Category;
            var displayName = inventoryItem.DisplayName;
            var description = inventoryItem.Description;
            var itemClass = inventoryItem.ItemClass;
            var externalURL = inventoryItem.ExternalIconURL;
            var type = inventoryItem.Type;
            var prices = inventoryItem.Prices;

            var isEquippable = inventoryItem.IsEquippable;
            var isConsumable = inventoryItem.IsConsumable;
            var isStackable = inventoryItem.IsStackable;
            var isTradable = inventoryItem.IsTradable;
            var isRecipe = inventoryItem.IsRecipe;
            var isUpgradable = inventoryItem.IsUpgradable;
            var hasLifeTime = inventoryItem.HasLifeTime;
            var expiration = inventoryItem.Expiration;
            var purchaseDate = inventoryItem.PurchaseDate;
            var count = inventoryItem.Count;
            var purchasePrice = inventoryItem.PurchasePrice;
            var purchaseCurrency = inventoryItem.PurchaseCurrency;
            var purchaseAction = inventoryItem.PurchaseAction;
            var upgradeIndex = inventoryItem.UpgradeIndex;
            var equipped = inventoryItem.Equipped;
            var isInTrading = inventoryItem.IsInTrading;

            var customData = inventoryItem.GetCustomData<SwordData>();

            var customDataAsDictionary = inventoryItem.GetCustomDataAsDictionary();
            var attack = customDataAsDictionary["Attack"];
            var speed = customDataAsDictionary["Speed"];

        }
    }
}

CBSInventoryModule.RemoveInventoryItem - Remove item from inventory of current auth profile

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        var instanceID = "item instance id";
        Inventory.RemoveInventoryItem(instanceID, OnRemove);
    }

    private void OnRemove(CBSRemoveItemsResult result)
    {
        if (result.IsSuccess)
        {
            var profileID = result.ProfileID;
            var removedInstanceIDs = result.RemovedInstanceItemsIDs;
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

CBSInventoryModule.RemoveInventoryItems - Remove items from inventory of current auth profile

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        var instanceIDs = new string[] 
        {
            "instance id 1",
            "instance id 2",
            "instance id 3"
        };
        Inventory.RemoveInventoryItems(instanceIDs, OnRemove);
    }

    private void OnRemove(CBSRemoveItemsResult result)
    {
        if (result.IsSuccess)
        {
            var profileID = result.ProfileID;
            var removedInstanceIDs = result.RemovedInstanceItemsIDs;
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

CBSInventoryModule.RemoveInventoryItemsFromProfile - Remove items from inventory by profile id

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        var profileID = "profile ID";
        var instanceIDs = new string[] 
        {
            "instance id 1",
            "instance id 2",
            "instance id 3"
        };
        Inventory.RemoveInventoryItemsFromProfile(profileID, instanceIDs, OnRemove);
    }

    private void OnRemove(CBSRemoveItemsResult result)
    {
        if (result.IsSuccess)
        {
            var profileID = result.ProfileID;
            var removedInstanceIDs = result.RemovedInstanceIDs;
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

CBSInventoryModule.RemoveInventoryItemFromProfile - Remove item from inventory by profile id

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        var profileID = "profile ID";
        var instanceID = "item instance id";
        Inventory.RemoveInventoryItemFromProfile(profileID, instanceID, OnRemove);
    }

    private void OnRemove(CBSRemoveItemsResult result)
    {
        if (result.IsSuccess)
        {
            var profileID = result.ProfileID;
            var removedInstanceIDs = result.RemovedInstanceIDs;
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

CBSInventoryModule.ModifyUsesCount - Modify uses count of item. For stackable item - modify stack count, for consumable - consume count. Pass a negative "count" value to decrease uses count.

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        var instanceID = "item instance id";
        var count = 10;
        Inventory.ModifyUsesCount(instanceID, count, OnModify);
    }

    private void OnModify(CBSModifyItemUsesCountResult result)
    {
        if (result.IsSuccess)
        {
            var profileID = result.ProfileID;
            var instanceID = result.InstanceId;
            var itemInstance = result.UpdatedItem;
            var updatedCount = result.UpdatedCount;
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

CBSInventoryModule.ConsumeItem - Consume inventory item by item instance id.

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        var instanceID = "item instance id";
        var count = 10;
        Inventory.ConsumeItem(instanceID, count, OnConsume);
    }

    private void OnConsume(CBSConsumeInventoryItemResult result)
    {
        if (result.IsSuccess)
        {
            var profileID = result.ProfileID;
            var instanceID = result.InstanceId;
            var itemInstance = result.ConsumedItem;
            var leftCount = result.CountLeft;
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

CBSInventoryModule.GetLootboxes - Get loot boxes list from inventory.

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        Inventory.GetLootboxes(OnGet);
    }

    private void OnGet(CBSGetLootboxesResult result)
    {
        if (result.IsSuccess)
        {
            var lootboxes = result.Lootboxes;
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

CBSInventoryModule.GetLootboxesBadge - Get lootboxes badge. Get count of not opened lootboxes.

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        Inventory.GetLootboxesBadge(OnGet);
    }

    private void OnGet(CBSBadgeResult result)
    {
        if (result.IsSuccess)
        {
            var lootboxCount = result.Count;
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

CBSInventoryModule.GetLootboxesBadgeFromCache - Get lootboxes badge from cache. Get count of not opened lootboxes.

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        Inventory.GetLootboxesBadgeFromCache(OnGet);
    }

    private void OnGet(CBSBadgeResult result)
    {
        if (result.IsSuccess)
        {
            var lootboxCount = result.Count;
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

CBSInventoryModule.GetLootboxesByCategory - Get loot boxes list from inventory by category.

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        var category = "your category";
        Inventory.GetLootboxesByCategory(category, OnGet);
    }

    private void OnGet(CBSGetLootboxesResult result)
    {
        if (result.IsSuccess)
        {
            var lootboxes = result.Lootboxes;
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

CBSInventoryModule.GetLootboxesFromCache - Get last cached loot box list

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        Inventory.GetLootboxesFromCache(OnGet);
    }

    private void OnGet(CBSGetLootboxesResult result)
    {
        if (result.IsSuccess)
        {
            var lootboxes = result.Lootboxes;
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

CBSInventoryModule.EquipItem - Equip item from inventory.

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        var instanceID = "item instance id";
        Inventory.EquipItem(instanceID, OnEquip);
    }

    private void OnEquip(CBSChangeEquipStateResult result)
    {
        if (result.IsSuccess)
        {
            var item = result.InventoryItem;
            var equipState = result.IsEquip;
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

CBSInventoryModule.UnEquipItem - Unequip item from inventory

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        var instanceID = "item instance id";
        Inventory.UnEquipItem(instanceID, OnUnEquip);
    }

    private void OnUnEquip(CBSChangeEquipStateResult result)
    {
        if (result.IsSuccess)
        {
            var item = result.InventoryItem;
            var equipState = result.IsEquip;
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

CBSInventoryModule.SetItemDataByKey - Set unique data for item. For example, ID cells in the inventory. Not to be confused with Item Custom Data.

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        var instanceID = "item instance id";
        var dataKey = "data key";
        var dataValue = "data value";
        Inventory.SetItemDataByKey(instanceID, dataKey, dataValue, OnUpdateData);
    }

    private void OnUpdateData(CBSSetInventoryDataResult result)
    {
        if (result.IsSuccess)
        {
            var item = result.InventoryItem;
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

CBSInventoryModule.OpenLootbox - Open loot box and get reward.

using CBS;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        var lootBoxInstanceID = "item instance id";
        Inventory.OpenLootbox(lootBoxInstanceID, OnOpen);
    }

    private void OnOpen(CBSOpenLootboxResult result)
    {
        if (result.IsSuccess)
        {
            var grantedItems = result.GrantedItems;
            var currencies = result.Currencies;
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

CBSInventoryModule.GetInventoryItemFromCache - Get specific item from cache inventory.

using CBS;
using CBS.Example;
using CBS.Models;
using UnityEngine;

public class InventoryExample : MonoBehaviour
{
    private ICBSInventory Inventory { get; set; }

    private void Start()
    {
        Inventory = CBSModule.Get<CBSInventoryModule>();

        var instanceID = "item instance id";
        var item =  Inventory.GetInventoryItemFromCache(instanceID);

        var inventoryItem = item;
        var itemID = inventoryItem.ItemID;
        var category = inventoryItem.Category;
        var displayName = inventoryItem.DisplayName;
        var description = inventoryItem.Description;
        var itemClass = inventoryItem.ItemClass;
        var externalURL = inventoryItem.ExternalIconURL;
        var type = inventoryItem.Type;
        var prices = inventoryItem.Prices;

        var isEquippable = inventoryItem.IsEquippable;
        var isConsumable = inventoryItem.IsConsumable;
        var isStackable = inventoryItem.IsStackable;
        var isTradable = inventoryItem.IsTradable;
        var isRecipe = inventoryItem.IsRecipe;
        var isUpgradable = inventoryItem.IsUpgradable;
        var hasLifeTime = inventoryItem.HasLifeTime;
        var expiration = inventoryItem.Expiration;
        var purchaseDate = inventoryItem.PurchaseDate;
        var count = inventoryItem.Count;
        var purchasePrice = inventoryItem.PurchasePrice;
        var purchaseCurrency = inventoryItem.PurchaseCurrency;
        var purchaseAction = inventoryItem.PurchaseAction;
        var upgradeIndex = inventoryItem.UpgradeIndex;
        var equipped = inventoryItem.Equipped;
        var isInTrading = inventoryItem.IsInTrading;

        var customData = inventoryItem.GetCustomData<SwordData>();

        var customDataAsDictionary = inventoryItem.GetCustomDataAsDictionary();
        var attack = customDataAsDictionary["Attack"];
        var speed = customDataAsDictionary["Speed"];
    }
}

Last updated