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

57 lines
1.4 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;
/// <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 != this)
Destroy(Instance);
Instance = this;
}
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);
}
}