Currencies Manager

Presented by ICurrenciesManager interface, this system operates with in-game currencies. You can add or withdraw them via this manager, as well as get information about specific currency.

To use this system, inject ICurrenciesManager interface into your class, as shown below:

[Inject] private ICurrenciesManager currenciesManager;

Parameters in inspector

currencies – reference to serialized object which contains game currencies collection. By default, it refers to Assets/Scriptables/Economics/CurrenciesCollection.asset.

Available methods

void AddCurrency(CurrencyType currencyType, int amount)

This method adds a certain amount of currency of currencyType to player's in-game account. If amount is negative, currency will be withdrawn instead.

Examples:

currenciesManager.AddCurrency(CurrencyType.Soft, 100); //100 soft added
currenciesManager.AddCurrency(CurrencyType.Hard, -3); //3 hard withdrawn

void WithdrawCurrency(CurrencyType currencyType, int amount)

This method withdraws amount of currency of currencyType from player's in-game account. If player doesn't have enough amount of this currency, it will be set to 0.

Example:

currenciesManager.WithdrawCurrency(CurrencyType.Hard, 3);

int GetCurrencyAmount(CurrencyType currencyType)

This method returns current amount of currencyType currency on player's in-game account.

Example:

if (currenciesManager.GetCurrencyAmount(CurrencyType.Hard) >= 3)
{
    //Player has enough hard currency to spend
    currenciesManager.WithdrawCurrency(CurrencyType.Hard, 3);
}
else
{
    //Player doesn't have enough hard currency
    uiController.ShowMessageBox("Warning", "Not enough money!");
}

bool GetCurrencyInfo(CurrencyType currencyType, out CurrencyInfo currencyInfo)

This method writes information about currencyType currency into currencyInfo structure. In case of success (if it finds information about such currency), this method returns true, otherwise it returns false.

Example:

if (currenciesManager.GetCurrencyInfo(currencyType, out var info))
{
    currencyUISlot.SetData(info.Icon, currenciesManager.GetCurrencyAmount(currencyType));
}

Last updated