85 lines
1.8 KiB
C#
85 lines
1.8 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class AreaClearanceManager : MonoBehaviour
|
|
{
|
|
public static AreaClearanceManager Instance { get; private set; }
|
|
|
|
[SerializeField] private LevelExit levelExit;
|
|
private readonly HashSet<EnemyController> activeEnemies = new HashSet<EnemyController>();
|
|
private bool areaCleared = false;
|
|
|
|
public int RemainingEnemies => activeEnemies.Count;
|
|
public bool IsAreaCleared => areaCleared;
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance != null && Instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
else
|
|
{
|
|
Instance = this;
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
if (levelExit != null)
|
|
{
|
|
levelExit.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public void RegisterEnemy(EnemyController enemy)
|
|
{
|
|
if (enemy == null) return;
|
|
|
|
if (!activeEnemies.Contains(enemy))
|
|
{
|
|
activeEnemies.Add(enemy);
|
|
UpdateUI();
|
|
}
|
|
}
|
|
|
|
public void UnregisterEnemy(EnemyController enemy)
|
|
{
|
|
if (enemy == null) return;
|
|
|
|
if (activeEnemies.Contains(enemy))
|
|
{
|
|
activeEnemies.Remove(enemy);
|
|
UpdateUI();
|
|
|
|
if (activeEnemies.Count == 0 && !areaCleared)
|
|
{
|
|
UnlockArea();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void UnlockArea()
|
|
{
|
|
areaCleared = true;
|
|
if (levelExit != null)
|
|
{
|
|
levelExit.gameObject.SetActive(true);
|
|
}
|
|
|
|
if (UIController.Instance != null)
|
|
{
|
|
UIController.Instance.ShowNotification("Area Cleared! Proceed to Exit.");
|
|
}
|
|
}
|
|
|
|
private void UpdateUI()
|
|
{
|
|
if (UIController.Instance != null)
|
|
{
|
|
UIController.Instance.UpdateZombiesRemaining(activeEnemies.Count);
|
|
}
|
|
}
|
|
}
|
|
|