Configuration

The methods in the Configuration namespace allow you to retrieve items from the global economy configuration.

SyncConfigurationAsync() caches the latest version of your Economy configuration, after which you can call methods like GetCurrencies() to read your configuration from the cache. If you publish a new configuration, you must call SyncConfigurationAsync() again to update the cache.

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, GetCurrencies()), otherwise an exception is thrown.

C#

await EconomyService.Instance.Configuration.SyncConfigurationAsync();

Currencies

GetCurrencies

Retrieves all currencies from your cached configuration. Returns a list of CurrencyDefinition objects.

C#

List<CurrencyDefinition> definitions = EconomyService.Instance.Configuration.GetCurrencies();

GetCurrency

Retrieves a specific CurrencyDefinition using a currency ID from your cached configuration. Returns null if the currency doesn't exist.

C#

string currencyID = "GOLD_BARS";
CurrencyDefinition goldCurrencyDefinition = EconomyService.Instance.Configuration.GetCurrency(currencyID);

CurrencyDefinition

A CurrencyDefinition object represents a single currency configuration and contains the following data:

  • Id: The currency ID.
  • Name: The human readable currency name.
  • Type: The type of item as defined in the Economy Configuration page (for all CurrencyDefinition objects this will be CURRENCY).
  • Initial: The amount of currency a player is given initially.
  • Max: (Optional, a value of 0 indicates no maximum) The maximum amount of currency available for a player to own.
  • CustomData: Any custom data associated with this currency definition, as a Dictionary<string, object> (see Using CustomDataDeserializable).
  • Created: The date this currency was created. It is an EconomyDate object.
  • Modified: The date this currency was modified. It is an EconomyDate object.

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 CurrencyDefinition. It returns a PlayerBalance as specified in Player balances.

C#

string 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 InventoryItemDefinition objects.

C#

List<InventoryItemDefinition> definitions = EconomyService.Instance.Configuration.GetInventoryItems();

GetInventoryItem

Retrieves a specific InventoryItemDefinition using an item ID from your cached configuration. Returns null if the item doesn't exist.

C#

string itemID = "SWORD";
InventoryItemDefinition definition = EconomyService.Instance.Configuration.GetInventoryItem(itemID);

InventoryItemDefinition

A InventoryItemDefinition object represents a single inventory item configuration, and contains the following data:

  • Id: The inventory item ID.
  • Name: The human readable name.
  • Type: The type of item as defined in the Economy Configuration page (for all InventoryItemDefinition objects this will be INVENTORY_ITEM).
  • CustomData: Any custom data associated with this item definition, as a Dictionary<string, object> (see Using CustomDataDeserializable).
  • Created: The date this item was created. It is an EconomyDate object.
  • Modified: The date this item was modified. It is an EconomyDate object.

It also contains the following helper methods:

GetAllPlayersInventoryItems

Gets all of the player's inventory items for the currently logged in player. Returns a GetInventoryResult as defined in Player inventories.

C#

string 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 VirtualPurchaseDefinition objects.

C#

List<VirtualPurchaseDefinition> definitions = EconomyService.Instance.Configuration.GetVirtualPurchases();

GetVirtualPurchase

Retrieves a single virtual purchase from your cached configuration. Returns a single VirtualPurchaseDefinition object.

C#

string purchaseId = "VIRTUAL_PURCHASE_ID"
VirtualPurchaseDefinition definition = EconomyService.Instance.Configuration.GetVirtualPurchase(purchaseId);

VirtualPurchaseDefinition

A VirtualPurchaseDefinition object represents a virtual purchase definition from your configuration. It is made up of a number of component objects as listed below.

The VirtualPurchaseDefinition has the following fields:

  • Id: The purchase definition ID.
  • Name: The human readable name.
  • Type: The type of item as defined in the Economy Configuration page (for all VirtualPurchaseDefinition objects this will be VIRTUAL_PURCHASE).
  • CustomData: Any custom data associated with this purchase definition, as a Dictionary<string, object> (see Using CustomDataDeserializable).
  • CustomDataDeserializable: Any custom data associated with this purchase definition, as an IDeserializable (see Using CustomDataDeserializable).
  • Created: The date this purchase definition was created. It is an EconomyDate object.
  • Modified: The date this purchase definition was modified. It is an EconomyDate object.
  • Costs: A list of the costs associated with this purchase, as a PurchaseItemQuantity.
  • Rewards: A list of the rewards associated with this purchase, as a PurchaseItemQuantity.

Real money purchases

Economy SDK 3.0.0 contains an issue that causes the GetRealMoneyPurchase()) / GetRealMoneyPurchases() methods to not return StoreIdentifiers. The recommended best practice is that developers revert to version 2.0.4 of the SDK to avoid this issue until it is resolved.

GetRealMoneyPurchases

Retrieves all real money purchases from your cached configuration. Returns a list of RealMoneyPurchaseDefinition objects.

C#

List<RealMoneyPurchaseDefinition> definitions = EconomyService.Instance.Configuration.GetRealMoneyPurchases();

GetRealMoneyPurchase

Retrieves a single real money purchase from your cached configuration. Returns a single RealMoneyPurchaseDefinition object.

C#

string purchaseId = "REAL_MONEY_PURCHASE_ID"
RealMoneyPurchaseDefinition definition = EconomyService.Instance.Configuration.GetRealMoneyPurchase(purchaseId);

RealMoneyPurchaseDefinition

A RealMoneyPurchaseDefinition object represents a real money purchase definition from your configuration. It is made up of a number of component objects as listed below.

The RealMoneyPurchaseDefinition has the following fields:

  • Id: The purchase definition ID.
  • Name: The human readable name.
  • Type: The type of item as defined in the Economy Configuration page (for all RealMoneyPurchaseDefinition objects this will be MONEY_PURCHASE).
  • CustomData: Any custom data associated with this purchase definition, as a Dictionary<string, object> (see Using CustomDataDeserializable).
  • Created: The date this purchase definition was created. It is an EconomyDate object.
  • Modified: The date this purchase definition was modified. It is an EconomyDate object.
  • StoreIdentifiers: The store identifiers for this purchase. It is a StoreIdentifiers object.
  • Rewards: A list of the rewards associated with this purchase, as a PurchaseItemQuantity.

StoreIdentifiers

A StoreIdentifers 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".

PurchaseItemQuantity

A PurchaseItemQuantity 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:

  • Item: An EconomyReference pointing to the item definition represented by this quantity.
  • Amount: The amount of the item represented, as an integer.

EconomyReference

An EconomyReference is a reference to another definition from within the purchase. It has a single method:

  • GetReferencedConfigurationItem() which fetches the associated item.

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 Cloud 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 CustomDataDeserializable on fetched configuration items. It is of type IDeserializable. This allows you to deserialize your items’ custom data into your own custom classes.

For example, if your game has a color rarity system then the items could have the following JSON code in the Unity Cloud Dashboard:

JSON

{
    "rarity": "purple"
}

You can deserialize the instance data with the following:

C#

class MyCustomData{
    public string Rarity
}
MyCustomData fetchedCustomData = fetchedConfigItem.CustomDataDeserializable.GetAs<MyCustomData>();
string rarity = fetchedCustomData.Rarity;