2026-04-22 15:58:44 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace Platformer.Mechanics
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2026-05-19 16:02:47 +00:00
|
|
|
/// BT13-Dev-Map Phase 2-C — 거점 영역 SpawnPoint.
|
|
|
|
|
/// PD §15 OVERRIDE 2건 (2026-05-18):
|
|
|
|
|
/// §15-7 OVERRIDE — 재-spawn timer·count 옵션 추가 (사망 후 자동 재 spawn).
|
|
|
|
|
/// §15-8 OVERRIDE — Enemy.prefab + MonsterRandomizer 활용 (단일 prefab spawn).
|
2026-04-22 15:58:44 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public class SpawnPoint : MonoBehaviour
|
|
|
|
|
{
|
2026-05-19 16:02:47 +00:00
|
|
|
[Header("Spawn 영역 — PD §15-8 OVERRIDE (2026-05-18) MonsterRandomizer 활용")]
|
|
|
|
|
public GameObject enemyPrefab; // baseEnemyPrefab (Enemy.prefab) — MonsterRandomizer 영역 random controller
|
2026-04-22 15:58:44 +00:00
|
|
|
|
2026-05-19 16:02:47 +00:00
|
|
|
[Header("Spawn radius — 거점 ±X random spawn")]
|
|
|
|
|
public float spawnRadiusX = 0.5f;
|
|
|
|
|
|
|
|
|
|
[Header("동시 spawn 상한")]
|
|
|
|
|
public int initialSpawnCount = 1;
|
|
|
|
|
public int maxConcurrent = 1;
|
|
|
|
|
|
|
|
|
|
[Header("재-spawn — PD §15-7 OVERRIDE (2026-05-18)")]
|
|
|
|
|
[Tooltip("Enemy 사망 후 재-spawn 대기 시간 (초) — 0 이하 시 재-spawn X")]
|
|
|
|
|
public float respawnTimer = 5f;
|
|
|
|
|
[Tooltip("최대 재-spawn 횟수 — -1: 무제한·0: 재-spawn X·N: N회")]
|
|
|
|
|
public int respawnMaxCount = -1;
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
[Header("미리보기 영역 — Editor only")]
|
|
|
|
|
public Color gizmoColor = new Color(1f, 0.3f, 0.3f, 0.5f);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
private GameObject _currentEnemy;
|
|
|
|
|
private int _spawnedCount = 0;
|
|
|
|
|
private float _lastDeathTime = -1f;
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
if (enemyPrefab == null) return;
|
|
|
|
|
int spawnCount = Mathf.Clamp(initialSpawnCount, 0, maxConcurrent);
|
|
|
|
|
for (int i = 0; i < spawnCount; i++)
|
|
|
|
|
{
|
|
|
|
|
SpawnEnemy();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
// PD §15-7 OVERRIDE — 재-spawn 메커니즘.
|
|
|
|
|
if (enemyPrefab == null) return;
|
|
|
|
|
if (respawnTimer <= 0f) return; // 재-spawn X
|
|
|
|
|
if (respawnMaxCount == 0) return; // 재-spawn 영역 0회
|
|
|
|
|
|
|
|
|
|
// _currentEnemy 영역 null·destroy 영역 — death 시점 lastDeathTime 갱신
|
|
|
|
|
if (_currentEnemy == null)
|
|
|
|
|
{
|
|
|
|
|
if (_lastDeathTime < 0f)
|
|
|
|
|
{
|
|
|
|
|
_lastDeathTime = Time.time;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (Time.time - _lastDeathTime < respawnTimer) return;
|
|
|
|
|
if (respawnMaxCount > 0 && _spawnedCount >= initialSpawnCount + respawnMaxCount) return;
|
|
|
|
|
SpawnEnemy();
|
|
|
|
|
_lastDeathTime = -1f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpawnEnemy()
|
|
|
|
|
{
|
|
|
|
|
Vector3 pos = transform.position + new Vector3(
|
|
|
|
|
Random.Range(-spawnRadiusX, spawnRadiusX), 0f, 0f);
|
|
|
|
|
_currentEnemy = Instantiate(enemyPrefab, pos, Quaternion.identity);
|
|
|
|
|
_spawnedCount++;
|
|
|
|
|
// EnemyController.Awake 영역 _startX·_startY 자동 set (BT102 정합)
|
|
|
|
|
// EnemyController.Start 영역 MeasureSafeWalkDistance(Tilemap WorldToCell + HasTile) 자동 측정
|
|
|
|
|
// MonsterRandomizer.Awake 영역 6종 controller random·sprite 영역 자동 적용 (§15-8 OVERRIDE)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
void OnDrawGizmos()
|
|
|
|
|
{
|
|
|
|
|
Gizmos.color = gizmoColor;
|
|
|
|
|
Gizmos.DrawWireSphere(transform.position, 0.5f);
|
|
|
|
|
Gizmos.DrawLine(transform.position + Vector3.left * spawnRadiusX,
|
|
|
|
|
transform.position + Vector3.right * spawnRadiusX);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2026-04-22 15:58:44 +00:00
|
|
|
}
|
2026-05-19 16:02:47 +00:00
|
|
|
}
|