건설 토대 및 상호작용 시스템 추가

This commit is contained in:
2026-01-27 22:50:57 +09:00
parent 805d526b27
commit 387991caab
17 changed files with 1779 additions and 184 deletions

View File

@@ -153,6 +153,7 @@ namespace Northbound
return;
}
// 완성 건물 프리팹으로 프리뷰 생성 (사용자가 완성 모습을 볼 수 있도록)
previewObject = Instantiate(data.prefab);
// Remove NetworkObject component from preview
@@ -162,6 +163,13 @@ namespace Northbound
Destroy(netObj);
}
// Remove Building component from preview
Building building = previewObject.GetComponent<Building>();
if (building != null)
{
Destroy(building);
}
// Apply ghost materials
previewRenderers = previewObject.GetComponentsInChildren<Renderer>();
foreach (var renderer in previewRenderers)
@@ -204,7 +212,7 @@ namespace Northbound
// Check if placement is valid
bool isValid = BuildingManager.Instance.IsValidPlacement(data, hit.point, currentRotation, out Vector3 snappedPosition);
// Update preview position
// Update preview position (placementOffset 적용)
previewObject.transform.position = snappedPosition + data.placementOffset;
previewObject.transform.rotation = Quaternion.Euler(0, currentRotation * 90f, 0);
@@ -231,23 +239,25 @@ namespace Northbound
private void OnBuild(InputAction.CallbackContext context)
{
if (!isBuildModeActive || previewObject == null || BuildingManager.Instance == null)
return;
if (!isBuildModeActive || previewObject == null) return;
BuildingData data = BuildingManager.Instance.availableBuildings[selectedBuildingIndex];
Vector3 placementPosition = previewObject.transform.position - data.placementOffset;
// Validate placement one more time
if (BuildingManager.Instance.IsValidPlacement(data, placementPosition, currentRotation, out Vector3 snappedPosition))
// Get placement position
Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue());
if (Physics.Raycast(ray, out RaycastHit hit, maxPlacementDistance, groundLayer))
{
// 🔥 변경: PlaceBuildingServerRpc 대신 RequestPlaceBuilding 호출
BuildingManager.Instance.RequestPlaceBuilding(selectedBuildingIndex, snappedPosition, currentRotation);
BuildingData selectedData = BuildingManager.Instance.availableBuildings[selectedBuildingIndex];
Debug.Log($"<color=cyan>[BuildingPlacement] 건물 배치 요청: {data.buildingName}</color>");
}
else
{
Debug.LogWarning("<color=yellow>[BuildingPlacement] 건물을 배치할 수 없는 위치입니다.</color>");
if (BuildingManager.Instance.IsValidPlacement(selectedData, hit.point, currentRotation, out Vector3 groundPosition))
{
// 토대 배치 요청 (실제로는 토대가 생성됨)
BuildingManager.Instance.RequestPlaceFoundation(selectedBuildingIndex, groundPosition, currentRotation);
Debug.Log($"<color=green>[BuildingPlacement] 토대 배치 요청: {selectedData.buildingName}</color>");
}
else
{
Debug.LogWarning("<color=yellow>[BuildingPlacement] 배치할 수 없는 위치입니다.</color>");
}
}
}