82 lines
1.9 KiB
C#
82 lines
1.9 KiB
C#
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
public class CombatRoomController : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
public GameObject doorBlockers;
|
|||
|
|
|
|||
|
|
[Header("Debug")]
|
|||
|
|
public bool logDoorState = true; // ✅ 체크하면 로그 출력
|
|||
|
|
|
|||
|
|
private bool activated = false;
|
|||
|
|
private readonly List<EnemyRoomLink> enemies = new List<EnemyRoomLink>();
|
|||
|
|
|
|||
|
|
void Awake()
|
|||
|
|
{
|
|||
|
|
if (doorBlockers != null)
|
|||
|
|
doorBlockers.SetActive(false);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void ActivateRoom()
|
|||
|
|
{
|
|||
|
|
if (activated) return;
|
|||
|
|
activated = true;
|
|||
|
|
|
|||
|
|
if (doorBlockers != null)
|
|||
|
|
doorBlockers.SetActive(true);
|
|||
|
|
|
|||
|
|
RefreshEnemies();
|
|||
|
|
|
|||
|
|
if (logDoorState)
|
|||
|
|
Debug.Log($"[Room] ENTER -> Door CLOSE, enemies={enemies.Count}", this);
|
|||
|
|
|
|||
|
|
TryUnlock();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void RefreshEnemies()
|
|||
|
|
{
|
|||
|
|
enemies.Clear();
|
|||
|
|
enemies.AddRange(GetComponentsInChildren<EnemyRoomLink>(true));
|
|||
|
|
enemies.RemoveAll(x => x == null);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void RegisterEnemy(EnemyRoomLink e)
|
|||
|
|
{
|
|||
|
|
if (e == null) return;
|
|||
|
|
if (!enemies.Contains(e))
|
|||
|
|
{
|
|||
|
|
enemies.Add(e);
|
|||
|
|
enemies.RemoveAll(x => x == null);
|
|||
|
|
|
|||
|
|
if (logDoorState)
|
|||
|
|
Debug.Log($"[Room] Enemy REGISTER -> enemies={enemies.Count}", this);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void NotifyEnemyDied(EnemyRoomLink e)
|
|||
|
|
{
|
|||
|
|
enemies.Remove(e);
|
|||
|
|
enemies.RemoveAll(x => x == null);
|
|||
|
|
|
|||
|
|
if (logDoorState)
|
|||
|
|
Debug.Log($"[Room] Enemy DEAD -> enemies={enemies.Count}", this);
|
|||
|
|
|
|||
|
|
TryUnlock();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void TryUnlock()
|
|||
|
|
{
|
|||
|
|
if (!activated) return;
|
|||
|
|
|
|||
|
|
enemies.RemoveAll(x => x == null);
|
|||
|
|
|
|||
|
|
if (enemies.Count == 0 && doorBlockers != null)
|
|||
|
|
{
|
|||
|
|
doorBlockers.SetActive(false);
|
|||
|
|
|
|||
|
|
if (logDoorState)
|
|||
|
|
Debug.Log("[Room] CLEAR -> Door OPEN", this);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|