meta파일 추가 및 gitignore에서 제거
This commit is contained in:
@@ -6,15 +6,16 @@ using System.Collections.Generic;
|
||||
public class BuildManager : MonoBehaviour
|
||||
{
|
||||
public static BuildManager Instance;
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
public struct TurretData // 타워별 정보를 담는 구조체
|
||||
public struct TurretData
|
||||
{
|
||||
public string turretName;
|
||||
public GameObject finalPrefab; // 완공 후 실제 타워
|
||||
public GameObject ghostPrefab; // 건설 모드 시 미리보기
|
||||
public float buildTime; // 건설 소요 시간
|
||||
public Vector2Int size; // 점유 칸수
|
||||
public bool isTunnel; // [추가] 터널 여부 체크
|
||||
public GameObject finalPrefab;
|
||||
public GameObject ghostPrefab;
|
||||
public float buildTime;
|
||||
public Vector2Int size;
|
||||
}
|
||||
|
||||
public bool IsBuildMode => isBuildMode;
|
||||
@@ -216,32 +217,48 @@ public class BuildManager : MonoBehaviour
|
||||
}
|
||||
|
||||
// --- Utilities ---
|
||||
private bool CanBuild(Vector2Int startPos, Vector2Int size)
|
||||
private bool CanBuild(Vector2Int startPos, TurretData data)
|
||||
{
|
||||
for (int x = 0; x < size.x; x++)
|
||||
for (int y = 0; y < size.y; y++)
|
||||
if (_occupiedNodes.Contains(new Vector2Int(startPos.x + x, startPos.y + y)))
|
||||
// 1. 기존 점유 노드 및 플레이어 충돌 체크 (기존 로직)
|
||||
for (int x = 0; x < data.size.x; x++)
|
||||
for (int y = 0; y < data.size.y; y++)
|
||||
if (_occupiedNodes.Contains(new Vector2Int(startPos.x + x, startPos.y + y)))
|
||||
return false;
|
||||
|
||||
// 2. 플레이어와 겹치는지 물리적 박스 검사
|
||||
Vector3 center = GridToWorld(startPos, size);
|
||||
// 타워 높이의 절반 정도 위에서 검사 (y축 위치 보정)
|
||||
center.y = 1f;
|
||||
// 2. 터널 연결 제약 조건 체크
|
||||
if (data.isTunnel)
|
||||
{
|
||||
return IsConnectedToExistingTunnel(startPos, data);
|
||||
}
|
||||
|
||||
// 타워 사이즈보다 아주 살짝 작게 설정하여 여유 공간 부여 (0.45f)
|
||||
Vector3 halfExtents = new Vector3(size.x * 0.45f, 0.5f, size.y * 0.45f);
|
||||
|
||||
// 해당 영역에 playerLayer를 가진 콜라이더가 있는지 확인
|
||||
bool isPlayerOverlapping = Physics.CheckBox(center, halfExtents, Quaternion.identity, playerLayer);
|
||||
|
||||
return !isPlayerOverlapping;
|
||||
return true; // 일반 타워는 어디든 건설 가능 (필요시 수정)
|
||||
}
|
||||
|
||||
private Vector2Int WorldToGrid(Vector3 worldPos) => new Vector2Int(Mathf.FloorToInt(worldPos.x / cellSize), Mathf.FloorToInt(worldPos.z / cellSize));
|
||||
|
||||
private Vector3 GridToWorld(Vector2Int gridPos, Vector2Int size)
|
||||
private bool IsConnectedToExistingTunnel(Vector2Int startPos, TurretData data)
|
||||
{
|
||||
return new Vector3(gridPos.x * cellSize + (size.x - 1) * cellSize * 0.5f, 0.05f, gridPos.y * cellSize + (size.y - 1) * cellSize * 0.5f);
|
||||
// [중요] 게임의 첫 번째 터널을 지을 수 있도록, 기존 터널이 아예 없다면 true 반환
|
||||
// 혹은 '코어(성벽)' 레이어를 체크하도록 할 수도 있습니다.
|
||||
if (_occupiedNodes.Count == 0) return true;
|
||||
|
||||
// 현재 배치하려는 고스트의 위치 근처에 이미 완성된 TunnelNode가 있는지 검사합니다.
|
||||
Vector3 ghostWorldPos = GridToWorld(startPos, data.size);
|
||||
|
||||
// 고스트 프리팹에 있는 노드들의 상대 위치를 활용해 주변을 검색합니다.
|
||||
// 여기서는 간단하게 고스트의 일정 반경 내에 Tunnel 레이어가 있는지 확인합니다.
|
||||
float checkRadius = cellSize * 1.5f; // 한 칸 정도의 여유 범위
|
||||
Collider[] neighbors = Physics.OverlapSphere(ghostWorldPos, checkRadius, LayerMask.GetMask("Tunnel"));
|
||||
|
||||
foreach (var col in neighbors)
|
||||
{
|
||||
// 건설 중인 '토대'가 아니라, 이미 '완공된' 터널 노드인지 확인해야 합니다.
|
||||
TunnelNode node = col.GetComponent<TunnelNode>();
|
||||
if (node != null && node.gameObject.activeInHierarchy)
|
||||
{
|
||||
return true; // 연결 가능한 노드 발견!
|
||||
}
|
||||
}
|
||||
|
||||
return false; // 주변에 연결된 터널이 없음
|
||||
}
|
||||
|
||||
private void OnDrawGizmos()
|
||||
|
||||
Reference in New Issue
Block a user