클라이언트에서 밝혀지지 않은 곳의 적이 보이는 문제 수정

This commit is contained in:
2026-02-25 23:35:18 +09:00
parent 9c6a9910cb
commit 93d326e692
4 changed files with 243 additions and 18 deletions

View File

@@ -219,7 +219,7 @@ namespace Northbound
[Header("Editor Settings")]
[Tooltip("Disable fog of war in Unity Editor for easier development")]
public bool disableInEditor = true;
public bool disableInEditor = false;
// 서버: 각 플레이어별 가시성 맵
private Dictionary<ulong, FogOfWarData> _serverFogData = new Dictionary<ulong, FogOfWarData>();
@@ -250,11 +250,18 @@ namespace Northbound
{
// Server: Register client connected callback to initialize fog data
NetworkManager.Singleton.OnClientConnectedCallback += OnClientConnected;
// 호스트 자신의 데이터도 초기화 (OnClientConnected가 호스트에게는 호출되지 않을 수 있음)
ulong hostClientId = NetworkManager.Singleton.LocalClientId;
if (!_serverFogData.ContainsKey(hostClientId))
{
_serverFogData[hostClientId] = new FogOfWarData(gridWidth, gridHeight);
}
}
if (IsClient && !IsServer)
// 클라이언트는 로컬 데이터 초기화 (호스트 포함)
if (IsClient)
{
// 클라이언트는 로컬 데이터 초기화
_localFogData = new FogOfWarData(gridWidth, gridHeight);
}
}
@@ -262,7 +269,7 @@ namespace Northbound
private void OnClientConnected(ulong clientId)
{
if (!IsServer) return;
// Ensure fog data exists for this client
if (!_serverFogData.ContainsKey(clientId))
{
@@ -317,13 +324,18 @@ namespace Northbound
/// </summary>
public FogOfWarData GetPlayerFogData(ulong clientId)
{
// 클라이언트는 자신의 로컬 데이터 반환
if (IsClient && !IsServer)
// 클라이언트(호스트 포함)는 자신의 로컬 데이터 반환
// 서버에서 계산된 시야 데이터는 ClientRpc로 동기화됨
if (IsClient)
{
if (_localFogData == null)
{
_localFogData = new FogOfWarData(gridWidth, gridHeight);
}
return _localFogData;
}
// 서버는 해당 클라이언트의 데이터 반환
// 순수 서버(전용 서버)의 경우 서버 데이터 반환
if (!_serverFogData.ContainsKey(clientId))
{
_serverFogData[clientId] = new FogOfWarData(gridWidth, gridHeight);
@@ -369,8 +381,11 @@ namespace Northbound
FogOfWarData fogData = kvp.Value;
// 해당 클라이언트가 여전히 연결되어 있는지 확인
if (NetworkManager.Singleton == null ||
!NetworkManager.Singleton.ConnectedClients.ContainsKey(clientId))
// 호스트의 경우 ConnectedClients에 없을 수 있으므로 별도 체크
bool isHost = (clientId == NetworkManager.Singleton.LocalClientId);
bool isConnected = NetworkManager.Singleton.ConnectedClients.ContainsKey(clientId);
if (!isHost && !isConnected)
{
continue;
}