적과 타워가 서로 공격하지 않는 문제 수정

This commit is contained in:
2026-02-24 16:08:35 +09:00
parent 907e2e24c8
commit 98d071480c
22 changed files with 883 additions and 365 deletions

View File

@@ -208,7 +208,7 @@ namespace Northbound
public void SetSelectedBuilding(int index)
{
if (index < 0 || BuildingManager.Instance == null ||
index >= BuildingManager.Instance.availableBuildings.Count)
index >= BuildingManager.Instance.GetBuildableBuildings().Count)
{
Debug.LogWarning($"[BuildingPlacement] 유효하지 않은 건물 인덱스: {index}");
return;
@@ -235,19 +235,22 @@ namespace Northbound
private void CreatePreview()
{
// 기존 프리뷰가 있다면 먼저 정리 (누적 방지)
DestroyPreview();
if (BuildingManager.Instance == null)
{
Debug.LogWarning("[BuildingPlacement] BuildingManager가 없습니다.");
return;
}
if (selectedBuildingIndex < 0 || selectedBuildingIndex >= BuildingManager.Instance.availableBuildings.Count)
if (selectedBuildingIndex < 0 || selectedBuildingIndex >= BuildingManager.Instance.GetBuildableBuildings().Count)
{
Debug.LogWarning($"[BuildingPlacement] 유효하지 않은 건물 인덱스: {selectedBuildingIndex}");
return;
}
TowerData data = BuildingManager.Instance.availableBuildings[selectedBuildingIndex];
TowerData data = BuildingManager.Instance.GetBuildableBuildings()[selectedBuildingIndex];
if (data == null)
{
Debug.LogError($"[BuildingPlacement] TowerData is NULL at index {selectedBuildingIndex}");
@@ -262,6 +265,9 @@ namespace Northbound
// 완성 건물 프리팹으로 프리뷰 생성 (사용자가 완성 모습을 볼 수 있도록)
previewObject = Instantiate(data.prefab);
// (0,0,0)에 고스트가 보이지 않도록 처음에는 비활성화
previewObject.SetActive(false);
// Remove NetworkObject component from preview
NetworkObject netObj = previewObject.GetComponent<NetworkObject>();
@@ -317,17 +323,19 @@ namespace Northbound
if (previewObject == null || BuildingManager.Instance == null)
return;
if (selectedBuildingIndex < 0 || selectedBuildingIndex >= BuildingManager.Instance.availableBuildings.Count)
if (selectedBuildingIndex < 0 || selectedBuildingIndex >= BuildingManager.Instance.GetBuildableBuildings().Count)
return;
TowerData data = BuildingManager.Instance.availableBuildings[selectedBuildingIndex];
TowerData data = BuildingManager.Instance.GetBuildableBuildings()[selectedBuildingIndex];
if (data == null || data.prefab == null)
return;
Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue());
if (Physics.Raycast(ray, out RaycastHit hit, maxPlacementDistance, groundLayer))
{
// Raycast 성공 시 프리뷰 표시
previewObject.SetActive(true);
// Check if placement is valid
bool isValid = BuildingManager.Instance.IsValidPlacement(data, hit.point, currentRotation, out Vector3 snappedPosition);
@@ -352,6 +360,11 @@ namespace Northbound
renderer.materials = mats;
}
}
else
{
// Raycast 실패 시 (0,0,0)에 고스트가 보이지 않도록 프리뷰 숨김
previewObject.SetActive(false);
}
}
private void OnRotate(InputAction.CallbackContext context)
@@ -443,13 +456,13 @@ namespace Northbound
{
if (BuildingManager.Instance == null) return;
if (selectedBuildingIndex < 0 || selectedBuildingIndex >= BuildingManager.Instance.availableBuildings.Count)
if (selectedBuildingIndex < 0 || selectedBuildingIndex >= BuildingManager.Instance.GetBuildableBuildings().Count)
{
Debug.LogWarning($"[BuildingPlacement] Invalid building index: {selectedBuildingIndex}");
return;
}
TowerData data = BuildingManager.Instance.availableBuildings[selectedBuildingIndex];
TowerData data = BuildingManager.Instance.GetBuildableBuildings()[selectedBuildingIndex];
if (data == null || data.prefab == null)
{
Debug.LogError($"[BuildingPlacement] TowerData or prefab is null at index {selectedBuildingIndex}. Please run 'Northbound > Populate Towers from Prefabs' and update BuildingManager.");
@@ -581,7 +594,7 @@ namespace Northbound
return;
}
TowerData selectedData = BuildingManager.Instance.availableBuildings[selectedBuildingIndex];
TowerData selectedData = BuildingManager.Instance.GetBuildableBuildings()[selectedBuildingIndex];
// Check affordability
var coreResourceManager = CoreResourceManager.Instance;
@@ -629,7 +642,7 @@ namespace Northbound
Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue());
if (Physics.Raycast(ray, out RaycastHit hit, maxPlacementDistance, groundLayer))
{
TowerData selectedData = BuildingManager.Instance.availableBuildings[selectedBuildingIndex];
TowerData selectedData = BuildingManager.Instance.GetBuildableBuildings()[selectedBuildingIndex];
// Check affordability
var coreResourceManager = CoreResourceManager.Instance;