Create your catalog programmatically
Use the CatalogProvider class to define your catalog in code for flexible or runtime-driven configurations.
Read time 1 minuteLast updated 24 days ago
You can define your catalog directly in code using the class. This approach gives you full programmatic control over your catalog configuration and is useful in complex scenarios, such as if you have a game with a very large catalog that constantly adds new items in large quantities.
CatalogProviderIf your catalog is static and you prefer a visual setup, you can configure listings using the IAP Catalog window in the Unity Editor instead. Refer to Create a catalog in the Editor for more information. You can still access a catalog created this way from your scripts. Refer to Fetch products from a catalog created in the Editor for more information.
To define catalog listings programmatically:
- During the initialization stage, create an instance of the class.
CatalogProvider - Use the method to add each listing, or
AddProduct()to add multiple listings at once.AddProducts() - For each listing, specify a unique cross-store and
Product ID.Product Type
The following example shows how to add a consumable listing with the ID to a , and later call to retrieve the defined listing.
100_gold_coinsCatalogProviderFetchProducts()using UnityEngine;using UnityEngine.Purchasing;public class MyIAPManager { public MyIAPManager () { var catalog = new CatalogProvider(); catalog.AddProduct("100_gold_coins", ProductType.Consumable); // Connect to the store catalog.FetchProducts(UnityIAPServices.DefaultProduct().FetchProductsWithNoRetries); }}