# Currencies Manager

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

```csharp
[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**.

**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.

### Available methods

```csharp
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:*

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

***

```csharp
void SetCurrencyAmount(CurrencyType currencyType, int amount)
```

*This method sets a certain **amount** of currency.*

***

```csharp
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:*

```csharp
currenciesManager.WithdrawCurrency(CurrencyType.Hard, 3);
```

***

```csharp
int GetCurrencyAmount(CurrencyType currencyType)
```

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

*Example:*

```csharp
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!");
}
```

***

```csharp
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:*

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

***

```csharp
void SaveState()
```

*This method saves currencies state.*


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://heroicsolo.gitbook.io/heroic-engine/basics/publish-your-docs/gameplay-systems/currencies-manager.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
