건물 업그레이드 기능
This commit is contained in:
@@ -296,6 +296,17 @@ namespace Northbound
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 토대 등록 (업그레이드 등으로 생성된 토대)
|
||||
/// </summary>
|
||||
public void RegisterFoundation(BuildingFoundation foundation)
|
||||
{
|
||||
if (!placedFoundations.Contains(foundation))
|
||||
{
|
||||
placedFoundations.Add(foundation);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 사전 배치 건물 등록 (씬에 미리 있는 건물용)
|
||||
/// </summary>
|
||||
@@ -516,5 +527,91 @@ namespace Northbound
|
||||
Destroy(buildingObj);
|
||||
}
|
||||
}
|
||||
|
||||
#region Upgrade System
|
||||
|
||||
/// <summary>
|
||||
/// ID로 TowerData 찾기
|
||||
/// </summary>
|
||||
public TowerData GetTowerDataById(int towerId)
|
||||
{
|
||||
foreach (var data in availableBuildings)
|
||||
{
|
||||
if (data != null && data.id == towerId)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 건물 업그레이드 (서버에서만 호출)
|
||||
/// </summary>
|
||||
public void UpgradeBuilding(Building building, TowerData upgradeData)
|
||||
{
|
||||
if (!IsServer) return;
|
||||
if (building == null || upgradeData == null) return;
|
||||
if (upgradeData.prefab == null)
|
||||
{
|
||||
Debug.LogError($"[BuildingManager] 업그레이드 프리팹이 없습니다: {upgradeData.buildingName}");
|
||||
return;
|
||||
}
|
||||
|
||||
// 기존 건물 정보 저장
|
||||
Vector3Int gridPos = building.gridPosition;
|
||||
int rotation = building.rotation;
|
||||
ulong ownerId = building.GetOwnerId();
|
||||
TeamType team = building.GetTeam();
|
||||
|
||||
// 기존 건물 제거
|
||||
placedBuildings.Remove(building);
|
||||
|
||||
// FogOfWar 시스템에서 제거
|
||||
if (building.buildingData != null && building.buildingData.providesVision)
|
||||
{
|
||||
FogOfWarSystem.Instance?.UnregisterVisionProvider(building);
|
||||
}
|
||||
|
||||
// 기존 건물 파괴
|
||||
building.NetworkObject.Despawn(true);
|
||||
|
||||
// 새 건물 생성
|
||||
Vector3 worldPosition = GridToWorld(gridPos);
|
||||
GameObject newBuildingObj = Instantiate(upgradeData.prefab, worldPosition + upgradeData.placementOffset, Quaternion.Euler(0, rotation * 90f, 0));
|
||||
NetworkObject netObj = newBuildingObj.GetComponent<NetworkObject>();
|
||||
|
||||
// FogOfWarVisibility 추가
|
||||
if (newBuildingObj.GetComponent<FogOfWarVisibility>() == null)
|
||||
{
|
||||
var visibility = newBuildingObj.AddComponent<FogOfWarVisibility>();
|
||||
visibility.showInExploredAreas = true;
|
||||
visibility.updateInterval = 0.2f;
|
||||
}
|
||||
|
||||
if (netObj != null)
|
||||
{
|
||||
netObj.SpawnWithOwnership(ownerId);
|
||||
|
||||
Building newBuilding = newBuildingObj.GetComponent<Building>();
|
||||
if (newBuilding == null)
|
||||
{
|
||||
newBuilding = newBuildingObj.AddComponent<Building>();
|
||||
}
|
||||
|
||||
// 새 건물 초기화
|
||||
newBuilding.Initialize(upgradeData, gridPos, rotation, ownerId, team);
|
||||
placedBuildings.Add(newBuilding);
|
||||
|
||||
Debug.Log($"<color=green>[BuildingManager] 건물 업그레이드 완료: {upgradeData.buildingName}</color>");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"<color=red>[BuildingManager] 업그레이드 프리팹에 NetworkObject가 없습니다!</color>");
|
||||
Destroy(newBuildingObj);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user