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:
currencies – reference to serialized object which contains game currencies collection. By default, it refers to Assets/Scriptables/Economics/CurrenciesCollection.asset.
saveAfterEachChange – if true, currencies manager will automatically save currencies state after the each currencies amount change. Otherwise, you'll need to call SaveState method manually when you need.
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:
This method returns current amount of currencyType currency on player's in-game account.
Example:
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.
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)
if (currenciesManager.GetCurrencyInfo(currencyType, out var info))
{
currencyUISlot.SetData(info.Icon, currenciesManager.GetCurrencyAmount(currencyType));
}