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

80 lines
1.8 KiB
C#

using System;
using UnityEngine;
public class GameManager : MonoBehaviour
{
public Observer<float> Balance = new(500f);
public static GameManager Instance;
public bool IsBuildMode = false;
private Tower selectedTower;
public float health = 0;
public float startHealth = 100;
public int CurrentNumEnemies = 0;
public float Volume = 10f;
/// <summary>
/// First param: isBuildMode
/// </summary>
public static event Action<bool> OnUpdateUIRequested;
public Tower SelectedTower { get { return selectedTower; } set {
if (selectedTower != null)
selectedTower.TowerSelected(false);
selectedTower = value;
if (selectedTower != null)
selectedTower.TowerSelected(true);
}}
private void Awake()
{
if (Instance != null)
{
Destroy(gameObject);
return;
}
Instance = this;
health = startHealth;
}
public void Reset()
{
foreach (var go in GameObject.FindObjectsByType<GameObject>(FindObjectsSortMode.None))
{
if (go != null && go != this.gameObject)
Destroy(go);
}
Destroy(this.gameObject);
}
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;
OnUpdateUIRequested?.Invoke(IsBuildMode);
}
private void m_finishBuildmode(TowerInfo info)
{
IsBuildMode = false;
OnUpdateUIRequested?.Invoke(IsBuildMode);
}
}