3DTD/Assets/Scripts/Manager/MoneyManager.cs

47 lines
1.2 KiB
C#
Raw Normal View History

2024-04-21 01:43:22 +02:00
using System;
2024-04-20 23:26:44 +02:00
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.Assertions;
public class MoneyManager : MonoBehaviour
{
2024-04-21 05:13:33 +02:00
public TowerCollection towerCollection;
2024-04-20 23:55:50 +02:00
[Space(10)]
2024-04-20 23:26:44 +02:00
public GameObject[] ShopButtons;
public TMP_Text[] MoneyTexts;
2024-04-21 01:43:22 +02:00
/// <summary>
/// Invoked when player selects tower from shop
/// </summary>
public static event Action<TowerInfo> OnShopSelected;
2024-04-20 23:26:44 +02:00
private void OnEnable()
{
for (int i = 0; i < ShopButtons.Length; i++)
{
var eventScript = ShopButtons[i].GetComponentInChildren<UITooltips>();
eventScript.ButtonIndex = i;
eventScript.OnClick += OnShopButtonClicked;
}
}
2024-04-20 23:55:50 +02:00
private void Start()
{
// Show prices
for (int i = 0; i < towerCollection.Towers.Length; i++)
{
MoneyTexts[i].text = towerCollection.Towers[i].price.ToString();
}
}
2024-04-20 23:26:44 +02:00
private void OnShopButtonClicked(int index)
{
Assert.AreNotEqual(index, -1, "Shop button not init-ed with index");
2024-04-21 01:43:22 +02:00
OnShopSelected?.Invoke(towerCollection.Towers[index]);
2024-04-20 23:55:50 +02:00
}
2024-04-20 23:26:44 +02:00
}