Configuration
Retrieve your Economy configuration using the Configuration namespace.
Read time 4 minutesLast updated 7 months ago
The methods in the namespace allow you to retrieve items from the global economy configuration.
ConfigurationSyncConfigurationAsync()GetCurrencies()SyncConfigurationAsync()SyncConfigurationAsync
Gets the currently published Economy configuration and caches it in the SDK. You must call this method before calling any other configuration methods (for example, ), otherwise an exception is thrown.
GetCurrencies()await EconomyService.Instance.Configuration.SyncConfigurationAsync();
Currencies
GetCurrencies
Retrieves all currencies from your cached configuration. Returns a list of objects.
CurrencyDefinitionList<CurrencyDefinition> definitions = EconomyService.Instance.Configuration.GetCurrencies();
GetCurrency
Retrieves a specific using a currency ID from your cached configuration. Returns if the currency doesn't exist.
CurrencyDefinitionnullstring currencyID = "GOLD_BARS";CurrencyDefinition goldCurrencyDefinition = EconomyService.Instance.Configuration.GetCurrency(currencyID);
CurrencyDefinition
A object represents a single currency configuration and contains the following data:
CurrencyDefinition- : The currency ID.
Id - : The human readable currency name.
Name - : The type of item as defined in the Economy Configuration page (for all
Typeobjects this will beCurrencyDefinition).CURRENCY - : The amount of currency a player is given initially.
Initial - : (Optional, a value of 0 indicates no maximum) The maximum amount of currency available for a player to own.
Max - : Any custom data associated with this currency definition, as a
CustomData(see Using CustomDataDeserializable).Dictionary<string, object> - : The date this currency was created. It is an EconomyDate object.
Created - : The date this currency was modified. It is an EconomyDate object.
Modified
It also has the following convenience methods:
GetPlayerBalance
This method gets the balance for the currently signed in player of the currency specified in the . It returns a as specified in Player balances.
CurrencyDefinitionPlayerBalancestring currencyID = "GOLD_BARS";CurrencyDefinition goldCurrencyDefinition = EconomyService.Instance.Configuration.GetCurrency(currencyID);PlayerBalance playersGoldBarBalance = await goldCurrencyDefinition.GetPlayerBalanceAsync();
Inventories
GetInventoryItems
Retrieves all inventory items from your cached configuration. Returns a list of objects.
InventoryItemDefinitionList<InventoryItemDefinition> definitions = EconomyService.Instance.Configuration.GetInventoryItems();
GetInventoryItem
Retrieves a specific using an item ID from your cached configuration. Returns if the item doesn't exist.
InventoryItemDefinitionnullstring itemID = "SWORD";InventoryItemDefinition definition = EconomyService.Instance.Configuration.GetInventoryItem(itemID);
InventoryItemDefinition
A object represents a single inventory item configuration, and contains the following data:
InventoryItemDefinition- : The inventory item ID.
Id - : The human readable name.
Name - : The type of item as defined in the Economy Configuration page (for all
Typeobjects this will beInventoryItemDefinition).INVENTORY_ITEM - : Any custom data associated with this item definition, as a
CustomData(see Using CustomDataDeserializable).Dictionary<string, object> - : The date this item was created. It is an EconomyDate object.
Created - : The date this item was modified. It is an EconomyDate object.
Modified
It also contains the following helper methods:
GetAllPlayersInventoryItems
Gets all of the player's inventory items for the currently logged in player. Returns a as defined in Player inventories.
GetInventoryResultstring itemID = "SWORD";InventoryItemDefinition definition = EconomyService.Instance.Configuration.GetInventoryItem(itemID);GetInventoryResult allThePlayersSwords = await definition.GetAllPlayersInventoryItemsAsync();
Purchases
Virtual purchases
GetVirtualPurchases
Retrieves all virtual purchases from your cached configuration. Returns a list of objects.
VirtualPurchaseDefinitionList<VirtualPurchaseDefinition> definitions = EconomyService.Instance.Configuration.GetVirtualPurchases();
GetVirtualPurchase
Retrieves a single virtual purchase from your cached configuration. Returns a single object.
VirtualPurchaseDefinitionstring purchaseId = "VIRTUAL_PURCHASE_ID"VirtualPurchaseDefinition definition = EconomyService.Instance.Configuration.GetVirtualPurchase(purchaseId);
VirtualPurchaseDefinition
A object represents a virtual purchase definition from your configuration. It is made up of a number of component objects as listed below.
VirtualPurchaseDefinitionThe has the following fields:
VirtualPurchaseDefinition- : The purchase definition ID.
Id - : The human readable name.
Name - : The type of item as defined in the Economy Configuration page (for all
Typeobjects this will beVirtualPurchaseDefinition).VIRTUAL_PURCHASE - : Any custom data associated with this purchase definition, as a
CustomData(see Using CustomDataDeserializable).Dictionary<string, object> - : Any custom data associated with this purchase definition, as an
CustomDataDeserializable(see Using CustomDataDeserializable).IDeserializable - : The date this purchase definition was created. It is an EconomyDate object.
Created - : The date this purchase definition was modified. It is an EconomyDate object.
Modified - : A list of the costs associated with this purchase, as a
Costs.PurchaseItemQuantity - : A list of the rewards associated with this purchase, as a
Rewards.PurchaseItemQuantity
Real money purchases
GetRealMoneyPurchases
Retrieves all real money purchases from your cached configuration. Returns a list of objects.
RealMoneyPurchaseDefinitionList<RealMoneyPurchaseDefinition> definitions = EconomyService.Instance.Configuration.GetRealMoneyPurchases();
GetRealMoneyPurchase
Retrieves a single real money purchase from your cached configuration. Returns a single object.
RealMoneyPurchaseDefinitionstring purchaseId = "REAL_MONEY_PURCHASE_ID"RealMoneyPurchaseDefinition definition = EconomyService.Instance.Configuration.GetRealMoneyPurchase(purchaseId);
RealMoneyPurchaseDefinition
A object represents a real money purchase definition from your configuration. It is made up of a number of component objects as listed below.
RealMoneyPurchaseDefinitionThe has the following fields:
RealMoneyPurchaseDefinition- : The purchase definition ID.
Id - : The human readable name.
Name - : The type of item as defined in the Economy Configuration page (for all
Typeobjects this will beRealMoneyPurchaseDefinition).MONEY_PURCHASE - : Any custom data associated with this purchase definition, as a
CustomData(see Using CustomDataDeserializable).Dictionary<string, object> - : The date this purchase definition was created. It is an EconomyDate object.
Created - : The date this purchase definition was modified. It is an EconomyDate object.
Modified - : The store identifiers for this purchase. It is a StoreIdentifiers object.
StoreIdentifiers - : A list of the rewards associated with this purchase, as a
Rewards.PurchaseItemQuantity
StoreIdentifiers
A object contains both the Google and Apple store identifiers. These are set when creating a purchase in the Unity Dashboard in the "Store connection" step. They can be edited by clicking on your purchase in the Unity Dashboard and scrolling down to "Store connection".
StoreIdentifersPurchaseItemQuantity
A represents an amount of currency/inventory items associated with a purchase. Each one relates to a single currency/inventory item type (for example, 4 swords, 10 gold, etc.). It has the following fields:
PurchaseItemQuantity- : An
Itempointing to the item definition represented by this quantity.EconomyReference - : The amount of the item represented, as an integer.
Amount
EconomyReference
An is a reference to another definition from within the purchase. It has a single method:
EconomyReference- which fetches the associated item.
GetReferencedConfigurationItem()
Getting the referenced item this way happens synchronously as it doesn't require a further network request, and will get the referenced item as it was when the purchase was retrieved (any changes to the definition between fetching the purchase and accessing the reference will not be reflected in the referenced item).
Using CustomDataDeserializable
Custom data is set in the Unity Dashboard. Select a currency, inventory item, or purchase, navigate to Custom data, then add the data in a JSON format.
Custom data is stored in on fetched configuration items. It is of type . This allows you to deserialize your items’ custom data into your own custom classes.
CustomDataDeserializableIDeserializableFor example, if your game has a color rarity system then the items could have the following JSON code in the Unity Dashboard:
{ "rarity": "purple"}
You can deserialize the instance data with the following:
class MyCustomData{ public string Rarity}MyCustomData fetchedCustomData = fetchedConfigItem.CustomDataDeserializable.GetAs<MyCustomData>();string rarity = fetchedCustomData.Rarity;