PLAY SDK Documentation
v0.12.0 (Obsolete)
v0.12.0 (Obsolete)
  • 🛠️ENVIRONMENT SETUP
    • Overview
    • PLAY Sample Package
  • 🖥️SDK Integration Guides
    • Getting Started
      • Unity
        • Tech Requirements
        • Step 1 - Import packages
        • Step 2 - Import credentials
        • Step 3 - Environments
        • Step 4 - Initialization
      • Unreal
        • Tech Requirements
        • Step 1 - Import packages
        • Step 2 - Configure credentials
        • Step 3 - Environments
        • Step 4 - Initialization
    • Authentication
      • Unity
      • Unreal
    • User Profile
      • Unity
      • Unreal
    • Virtual Items
      • Unity
      • Unreal
    • Inventory
      • Unity
      • Unreal
    • Store
      • Unity
      • Unreal
    • Currency (IAP)
      • Unity
      • Unreal
    • Achievements
      • Unity
      • Unreal
    • Game Progress
      • Unity
      • Unreal
    • Leaderboards
      • Unity
      • Unreal
    • Matchmaking
      • Unity
      • Unreal
    • Wallets
      • Unity
      • Unreal
    • Analytics
      • Unity
      • Unreal
    • Notifications
      • Unity
      • Unreal
    • Module Requests
  • 🎲Game Design Guides
    • Overview
    • User Authentication
    • User Profile
    • Game (Progression + Rewards)
    • Virtual Items
    • Currency (IAP)
    • Store
    • Inventory
    • Achievements
    • NFT Purchase Flow & Wallets
    • Limited-Time Offers
    • NFT Passes
  • 📌Links
    • PLAY Whitepaper
    • PLAY Postman API Doc
    • PLAY Dev Dashboard
    • PLAY Example Repository Dev
    • PLAY Example Repository Prod
    • Report an Issue
    • Discord dev-chat
    • Telegram Community Channel
    • Social Links
Powered by GitBook
On this page
  • Introduction
  • Retrieving inventory items with Virtual Items data
  • Add to inventory
  • Set Properties
  • Get properties

Was this helpful?

Export as PDF
  1. SDK Integration Guides
  2. Inventory

Unity

Unity integration

Introduction

After the user purchases a Virtual Item, it is automatically added to the user's Inventory during the transaction process. It is possible also to add a virtual item to the user's inventory without going through the purchase process for non-NFT items.

InventoryItem
  • id (string): Unique inventory id for this item.

  • virtualItemId (string): Id of the virtual item stored in the inventory.

  • quantity (int): Amount of items store in this inventory slot.

  • appIds (List<string>): List of project id where this item will be accessible.

  • tags (List<string>): List of tags used for filtering items.

  • properties (List<Property>): List of properties for this inventory item.

Retrieving inventory items with Virtual Items data

The following method gets all inventory items for the currently logged in player.

using System.Collections.Generic;
using UnityEngine;
using RGN.Modules.Inventory;

public class InventoryExamples : MonoBehaviour
{
    private async void GetUserInventory()
    {
        List<InventoryItemData> inventory = await InventoryModule.I.GetWithVirtualItemsDataForCurrentAppAsync();
        foreach (var inventoryItem in inventory)
        {
            Debug.Log($"Virtual item id : {inventoryItem.virtualItemId}");
            Debug.Log($"Virtual item name : {inventoryItem.virtualItem.name}");
        }
    }
}

Add to inventory

Add to inventory can be use to add regular virtual items into the player inventory. NFT's cannot be added to the inventory with this function.

using UnityEngine;
using RGN.Modules.Inventory;

public class InventoryExamples : MonoBehaviour
{
    private async void AddToUserInventory()
    {
        string virtualItemId = "virtualItemToAdd";
        await InventoryModule.I.AddToInventoryAsync(virtualItemId);
    }
}

Set Properties

using UnityEngine;
using RGN.Modules.Inventory;

public struct MyCustomProperties
{
    public int BonusHealth;
    public float DamageMultiplier;
}

public class InventoryExamples : MonoBehaviour
{
    private async void SetPropertiesInInventory()
    {
        string inventoryItemId = "inventoryItemId";

        MyCustomProperties customProperties = new MyCustomProperties
        {
            BonusHealth = 50,
            DamageMultiplier = 1.5f
        };
        string jsonProperties = JsonUtility.ToJson(customProperties);

        await InventoryModule.I.SetPropertiesAsync(inventoryItemId, jsonProperties);
    }
}

Get properties

using UnityEngine;
using RGN.Modules.Inventory;

public struct MyCustomProperties
{
    public int BonusHealth;
    public float DamageMultiplier;
}

public class InventoryExamples : MonoBehaviour
{
    private async void GetPropertiesInInventory()
    {
        string inventoryItemId = "inventoryItemId";
        string jsonProperties = await InventoryModule.I.GetPropertiesAsync(inventoryItemId);
        MyCustomProperties customProperties = JsonUtility.FromJson<MyCustomProperties>(jsonProperties);
        Debug.Log($"Bonus health : {customProperties.BonusHealth} \n" +
            $"Damage multiplier : {customProperties.DamageMultiplier}");
    }
}

Was this helpful?

🖥️