건설 퀵슬롯 생성

This commit is contained in:
2026-01-28 00:37:56 +09:00
parent 8799c4f8f4
commit 68a2e4e340
18 changed files with 2507 additions and 167 deletions

View File

@@ -1,6 +1,7 @@
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.EventSystems;
namespace Northbound
{
@@ -124,12 +125,51 @@ namespace Northbound
if (isBuildModeActive)
{
// UI 표시
if (BuildingQuickslotUI.Instance != null)
{
BuildingQuickslotUI.Instance.ShowQuickslot(this);
}
CreatePreview();
}
else
{
// UI 숨김
if (BuildingQuickslotUI.Instance != null)
{
BuildingQuickslotUI.Instance.HideQuickslot();
}
DestroyPreview();
}
Debug.Log($"[BuildingPlacement] 건설 모드 {(isBuildModeActive ? "" : "")}");
}
/// <summary>
/// UI에서 건물 선택 시 호출
/// </summary>
public void SetSelectedBuilding(int index)
{
if (index < 0 || BuildingManager.Instance == null ||
index >= BuildingManager.Instance.availableBuildings.Count)
{
Debug.LogWarning($"[BuildingPlacement] 유효하지 않은 건물 인덱스: {index}");
return;
}
selectedBuildingIndex = index;
currentRotation = 0; // 회전 초기화
// 프리뷰 다시 생성
if (isBuildModeActive)
{
DestroyPreview();
CreatePreview();
}
Debug.Log($"[BuildingPlacement] 건물 선택됨: {BuildingManager.Instance.availableBuildings[index].buildingName}");
}
private void CreatePreview()
@@ -187,6 +227,8 @@ namespace Northbound
{
collider.enabled = false;
}
Debug.Log($"[BuildingPlacement] 프리뷰 생성됨: {data.buildingName}");
}
private void DestroyPreview()
@@ -241,6 +283,13 @@ namespace Northbound
{
if (!isBuildModeActive || previewObject == null) return;
// UI 위에서 클릭한 경우 무시
if (IsPointerOverUI())
{
Debug.Log("<color=cyan>[BuildingPlacement] UI 위에서 클릭함 - 건설 취소</color>");
return;
}
// Get placement position
Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue());
if (Physics.Raycast(ray, out RaycastHit hit, maxPlacementDistance, groundLayer))
@@ -249,34 +298,43 @@ namespace Northbound
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>");
Debug.Log($"<color=cyan>[BuildingPlacement] 건설 시작: {selectedData.buildingName}</color>");
}
else
{
Debug.LogWarning("<color=yellow>[BuildingPlacement] 배치할 수 없는 위치입니다.</color>");
Debug.Log("<color=yellow>[BuildingPlacement] 배치할 수 없는 위치입니다.</color>");
}
}
}
private void OnDrawGizmos()
/// <summary>
/// 마우스 포인터가 UI 위에 있는지 확인
/// </summary>
private bool IsPointerOverUI()
{
if (!IsOwner || !isBuildModeActive || !showGridBounds) return;
if (BuildingManager.Instance == null || previewObject == null || !previewObject.activeSelf) return;
// EventSystem이 없으면 UI 체크 불가능
if (EventSystem.current == null)
return false;
BuildingData data = BuildingManager.Instance.availableBuildings[selectedBuildingIndex];
if (data == null) return;
// New Input System을 사용하는 경우
if (Mouse.current != null)
{
Vector2 mousePosition = Mouse.current.position.ReadValue();
return EventSystem.current.IsPointerOverGameObject();
}
// Draw grid bounds being used for collision detection
Bounds bounds = BuildingManager.Instance.GetPlacementBounds(data, previewObject.transform.position, currentRotation);
// Legacy Input System (폴백)
return EventSystem.current.IsPointerOverGameObject();
}
// Check if valid
bool isValid = BuildingManager.Instance.IsValidPlacement(data, previewObject.transform.position, currentRotation, out _);
Gizmos.color = isValid ? new Color(0, 1, 0, 0.5f) : new Color(1, 0, 0, 0.5f);
Gizmos.DrawWireCube(bounds.center, bounds.size);
/// <summary>
/// 건설 모드 활성화 상태 확인
/// </summary>
public bool IsBuildModeActive()
{
return isBuildModeActive;
}
}
}