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

68 lines
1.5 KiB
C#
Raw Normal View History

2024-04-21 01:43:22 +02:00
using System;
2024-04-20 22:05:01 +02:00
using UnityEngine;
public class GameManager : MonoBehaviour
{
2024-04-21 06:13:14 +02:00
public Observer<float> Balance = new(500f);
2024-04-20 22:05:01 +02:00
public static GameManager Instance;
2024-04-20 22:07:34 +02:00
public bool IsBuildMode = false;
2024-04-20 22:42:06 +02:00
private Tower selectedTower;
2024-04-21 00:02:41 +02:00
2024-04-21 07:50:06 +02:00
public float health = 0;
public float startHealth = 100;
2024-04-21 07:31:09 +02:00
public int CurrentNumEnemies = 0;
2024-04-21 07:33:18 +02:00
2024-04-21 03:07:29 +02:00
/// <summary>
/// First param: isBuildMode
/// </summary>
public static event Action<bool> OnUpdateUIRequested;
2024-04-20 22:42:06 +02:00
public Tower SelectedTower { get { return selectedTower; } set {
if (selectedTower != null)
selectedTower.TowerSelected(false);
selectedTower = value;
2024-04-20 23:32:42 +02:00
if (selectedTower != null)
selectedTower.TowerSelected(true);
2024-04-20 22:42:06 +02:00
}}
2024-04-20 22:07:34 +02:00
2024-04-20 22:20:20 +02:00
private void Awake()
2024-04-20 22:05:01 +02:00
{
2024-04-21 10:53:16 +02:00
if (Instance != null)
{
Destroy(gameObject);
return;
}
2024-04-20 22:05:01 +02:00
Instance = this;
2024-04-21 07:33:18 +02:00
health = startHealth;
2024-04-20 22:05:01 +02:00
}
2024-04-21 01:43:22 +02:00
private void OnEnable()
{
MoneyManager.OnShopSelected += m_OnTowerShopSelected;
TowerPlacementManager.OnTowerPlaced += m_finishBuildmode;
}
private void OnDisable()
{
MoneyManager.OnShopSelected -= m_OnTowerShopSelected;
TowerPlacementManager.OnTowerPlaced -= m_finishBuildmode;
}
private void m_OnTowerShopSelected(TowerInfo info)
{
IsBuildMode = true;
2024-04-21 03:07:29 +02:00
OnUpdateUIRequested?.Invoke(IsBuildMode);
2024-04-21 01:43:22 +02:00
}
private void m_finishBuildmode(TowerInfo info)
{
IsBuildMode = false;
2024-04-21 03:07:29 +02:00
OnUpdateUIRequested?.Invoke(IsBuildMode);
2024-04-21 01:43:22 +02:00
}
2024-04-20 22:05:01 +02:00
}