There is also a method overload for pagination requests. The pagination means you request not all items at once for the project, but in packs. For example every request can contain maximal 10 items. When you request the first time the startAfter need to by null or empty. For the subsequent requests you need to provide as the startAfter parameter the id of the last loaded virtual item:
usingSystem;usingSystem.Collections.Generic;usingRGN.Utility;namespaceRGN.Modules.VirtualItems{ [Serializable]publicclassVirtualItem { /// <summary> /// Unique id of the virtual item /// </summary>publicstring id; /// <summary> /// Virtual item name /// Is used also to store localization key for the name /// </summary>publicstring name; /// <summary> /// Virtual item description /// Is used also to store localization key for the description /// </summary>publicstring description; /// <summary> /// Date and time when the virtual item was created /// This field is automatically populated by the backend /// </summary>publiclong createdAt; /// <summary> /// Date and time when the virtual item data was last time updated /// This field is automatically populated by the backend /// </summary>publiclong updatedAt; /// <summary> /// User Id who created the virtual item /// This field is automatically populated by the backend /// </summary>publicstring createdBy; /// <summary> /// User Id who last time updated the item /// This field is automatically populated by the backend /// </summary>publicstring updatedBy; /// <summary> /// This field is used to indicate if an item can be stacked /// When you add stackable items to user inventory, the items count is increased /// When you add non stackable items to user inventory, this operation creates /// a new item in inventory /// Only non stackable items can be upgraded /// </summary>publicbool isStackable; /// <summary> /// Indicates if the virtual item is a NFT. /// Please use IsNFT() method to check if item is a NFT. /// The NFT virtual items require primary user wallet /// For more information see the API in WalletsModule /// </summary>publicbool isNFT; /// <summary> /// List of application ids where this item is used /// </summary>publicList<string> appIds =newList<string>(); /// <summary> /// List of tags to filter the items /// You can place multiple items into one category tag /// For example in a shooter game: "guns", "rifles" /// </summary>publicList<string> tags =newList<string>(); /// <summary> /// List of childs of the current virtual item. Virtual items ids list. /// It is used to build tree structure hierarchies. /// </summary>publicList<string> childs =newList<string>(); /// <summary> /// List of addressable ids for the virtual item binary data /// </summary>publicList<AddressableInfo> addressableIds; /// <summary> /// List of virtual item custom json. It is used to store game specific /// json in json format. /// For example: you can attach some json like "damage", "range", /// "fireRate" attached to this item /// </summary>publicList<Properties> properties; /// <summary> /// Array of prices for the virtual item /// A virtual item can be sold for different currencies with different prices /// It is also possible to combine two and more currencies to sell the item /// </summary>publicList<PriceInfo> prices; /// <summary> /// How much quantity of the goods left (use only for NFT items) /// </summary>publicint totalQuantity; // Not obsolete! Needed to query every compatible childspublicList<string> compatibleItemIds =newList<string>(); // List of parent ID // Not obsolete! Cannot have the material info inside json, because the material is needed in every gamespublicList<MaterialInfo> materialInfos =newList<MaterialInfo>(); // if the items as custom texture /// <summary> /// Checks if the item is NFT. It means the item was minted. /// The purchase process for NFT items goes throught blockchain /// </summary> /// <returns></returns>publicboolIsNFT(); /// <summary> /// Returns Virtual Item RGNCoin (rgn-coin) price. /// If the price can not be found throws InvalidOperationException /// </summary> /// <returns></returns> /// <exceptioncref="InvalidOperationException"></exception>publicintGetRGNCoinPrice(); /// <summary> /// Returns Custom Currency Price with provided currency name. /// If the price with currency name can not be found throws InvalidOperationException /// </summary> /// <paramname="currencyName">Valid currency name for current app/game</param> /// <returns></returns> /// <exceptioncref="InvalidOperationException"></exception>publicintGetCustomCoinPrice(string currencyName); }}
You can also provide an optional parameter appId to the GetByTagsAsync method call. This parameter works in combination with the method SetTagsAsync. The SetTagsAsync method has also an optional appId parameter. When this parameter is provided, we automatically attach appId to every tag in the tags array and query the database. This is specifically done to allow app developers to have unique tags for virtual items per app id.
It is possible to update the name, description and tags for virtual items:
usingSystem.Collections.Generic;usingRGN.Modules.VirtualItems;usingUnityEngine;namespaceSomeNamespace{internalsealedclassUpdatingVirtualItemsData {publicasyncvoidUpdateNameAndDescriptionAsync() {string virtualItemId ="some_virtual_item";awaitVirtualItemsModule.I.SetNameAsync(virtualItemId,"New Virtual Item Name");awaitVirtualItemsModule.I.SetDescriptionAsync(virtualItemId,"New Virtual Item Description"); }publicasyncvoidUpdateTagsAsync() {string virtualItemId ="some_virtual_item";var tags =newList<string> { "tag_one","tag_two","etc" }; // This will store "tag_one_my_unique_string", // "tag_two_my_unique_string", "etc_my_unique_string" // in the databaseawaitVirtualItemsModule.I.SetTagsAsync(virtualItemId, tags); } }}
Storing and getting custom json data :
It is possible the store and retrieve custom properties json string associated with virtual item. The data is stored in the virtual items data. The json string should be UTF8 formatted string not longer than 100k characters.
usingRGN.Modules.VirtualItems;usingUnityEngine;namespaceSomeNamespace{internalsealedclassSetAndGetProperties { [System.Serializable]internalsealedclassSerializable {publicint Integer;publicstring String;publicstring[] StringArray; }publicasyncvoidUpdateCustomGamePropertiesAsync() {string virtualItemId ="some_virtual_item";var gameSpecificData =newSerializable() { Integer =42, String ="Hello World", StringArray =newstring[] { "Some important game specific data" } };string propertiesJson =JsonUtility.ToJson(gameSpecificData); // Stores json string in virtual items data:awaitVirtualItemsModule.I.SetPropertiesAsync( virtualItemId, propertiesJson); // Retrieves the json properties string from the backendvar jsonProperties =awaitVirtualItemsModule.I.GetPropertiesAsync(virtualItemId);Serializable deserialized =JsonUtility.FromJson<Serializable>(jsonProperties);Debug.Log(deserialized.Integer); } }}