Purpose: Global in-game currency manager (Singleton). By default it saves and loads the balance using SaveProvider, and supports reactive properties (ReactiveProperty) for easy UI binding. You can disable persistence for session-only modes and demos (NoCode-friendly).
Money instances register themselves at runtime and can be resolved by save key:
Money gems = Money.FindBySaveKey("Gems");
bool found = Money.TryFindBySaveKey("Gems", out Money wallet);This is used by ShopItemData.CurrencyOverrideSaveKey, ShopBundleData.CurrencyOverrideSaveKey, and TextMoney.
If no key is selected, systems fall back to the usual Money.I singleton or the Shop default currency.
- Add the component via
Add Component > Neoxider > Shop > Moneyto a manager object in the scene (preferably a persistent prefab that survives scene loads). - Typically, one instance is used per game (
Money.I).
| Field | Description |
|---|---|
_moneySave |
The SaveProvider save key for the main balance. |
_persistMoney |
When enabled (default), balance is loaded on start and written on changes. When disabled, balance stays in memory only (no load/setfloat for currency keys). |
st_levelMoney |
References to SetText components for displaying current level earnings. |
st_money |
References to SetText components for displaying the global balance. |
t_levelMoney |
Direct references to TMP_Text components for level earnings. |
t_money |
Direct references to TMP_Text components for the main balance. |
You can access the manager from anywhere via the global singleton:
// Add 100 coins
Money.I.Add(100f);
// Try to spend 50 coins
bool success = Money.I.Spend(50f);
if (success) {
// Purchase successful
}
// Set balance (persists when persistence is on)
Money.I.SetMoney(500f);
// Alias for UnityEvent / buttons:
Money.I.SetCurrentMoney(500f);
// For regular uGUI Button.onClick use the void wrapper:
Money.I.SpendFromButton(50f);
// Remove persisted keys and reset runtime balance to zero
Money.I.ClearSavedMoneyAndReset();
// Reload balance from SaveProvider after external key changes
Money.I.ReloadBalanceFromSave();To display the balance in the UI, it is recommended to use the TextMoney component.
NoCode / UnityEvent: wire Add(float), SetCurrentMoney(float), ClearSavedMoneyAndReset(), and ReloadBalanceFromSave() to UnityEvent. Spend(float) returns bool, so regular Button.onClick does not list it; use SpendFromButton(float) for buttons. Use Spend(float) from code when you need the success/fail result.
- TextMoney - UI component for text display.
- Module Root