From 0a2119a5484f11f1929a762cac1c8739763adbbc Mon Sep 17 00:00:00 2001 From: dal4segno Date: Wed, 25 Feb 2026 21:45:06 +0900 Subject: [PATCH] =?UTF-8?q?=ED=8C=80=EC=9B=90=EB=93=A4=20=EB=AA=A8?= =?UTF-8?q?=EB=91=90=EA=B0=80=20=EC=8B=9C=EC=95=BC=EB=A5=BC=20=EA=B3=B5?= =?UTF-8?q?=EC=9C=A0=ED=95=98=EB=8F=84=EB=A1=9D=20=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/FogOfWarSystem.cs | 48 ++++++++++++++++++++++++-- Assets/Scripts/IVisionProvider.cs | 5 +++ Assets/Scripts/PlayerVisionProvider.cs | 1 + 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/FogOfWarSystem.cs b/Assets/Scripts/FogOfWarSystem.cs index fd27d62..37c1c6f 100644 --- a/Assets/Scripts/FogOfWarSystem.cs +++ b/Assets/Scripts/FogOfWarSystem.cs @@ -342,12 +342,14 @@ namespace Northbound fogData.ClearCurrentVision(); } - // 모든 시야 제공자의 시야 범위 계산 + // 모든 시야 제공자의 시야 범위 계산 (팀 시야 공유) foreach (var provider in _visionProviders) { if (provider == null || !provider.IsActive()) continue; ulong ownerId = provider.GetOwnerId(); + TeamType providerTeam = provider.GetTeam(); + if (!_serverFogData.ContainsKey(ownerId)) { _serverFogData[ownerId] = new FogOfWarData(gridWidth, gridHeight); @@ -356,7 +358,8 @@ namespace Northbound Vector3 position = provider.GetTransform().position; float visionRange = provider.GetVisionRange(); - RevealArea(ownerId, position, visionRange); + // 같은 팀의 모든 멤버에게 시야 공유 + RevealAreaForTeam(providerTeam, position, visionRange); } // 각 클라이언트에게 시야 데이터 전송 @@ -387,6 +390,47 @@ namespace Northbound } } + /// + /// 같은 팀의 모든 멤버에게 시야 공개 + /// + private void RevealAreaForTeam(TeamType team, Vector3 worldPosition, float radius) + { + // 해당 팀의 모든 멤버 찾기 + foreach (var kvp in _serverFogData) + { + ulong clientId = kvp.Key; + + // 클라이언트의 팀 확인 + if (GetClientTeam(clientId) == team) + { + RevealArea(clientId, worldPosition, radius); + } + } + } + + /// + /// 클라이언트의 팀 가져오기 + /// + private TeamType GetClientTeam(ulong clientId) + { + if (NetworkManager.Singleton == null) return TeamType.Neutral; + + // 연결된 클라이언트에서 플레이어 오브젝트 찾기 + if (NetworkManager.Singleton.SpawnManager.SpawnedObjects != null) + { + foreach (var netObj in NetworkManager.Singleton.SpawnManager.SpawnedObjects.Values) + { + var playerController = netObj.GetComponent(); + if (playerController != null && playerController.OwnerPlayerId == clientId) + { + return playerController.GetTeam(); + } + } + } + + return TeamType.Neutral; + } + /// /// 클라이언트에게 안개 데이터 전송 /// diff --git a/Assets/Scripts/IVisionProvider.cs b/Assets/Scripts/IVisionProvider.cs index a9ac83c..933624d 100644 --- a/Assets/Scripts/IVisionProvider.cs +++ b/Assets/Scripts/IVisionProvider.cs @@ -26,5 +26,10 @@ namespace Northbound /// 현재 활성화 상태인지 /// bool IsActive(); + + /// + /// 소속 팀 (팀 시야 공유용) + /// + TeamType GetTeam(); } } \ No newline at end of file diff --git a/Assets/Scripts/PlayerVisionProvider.cs b/Assets/Scripts/PlayerVisionProvider.cs index 17c8c88..459a6b1 100644 --- a/Assets/Scripts/PlayerVisionProvider.cs +++ b/Assets/Scripts/PlayerVisionProvider.cs @@ -35,6 +35,7 @@ namespace Northbound public float GetVisionRange() => _playerStats?.GetSight() ?? 10f; public Transform GetTransform() => transform; public bool IsActive() => IsSpawned; + public TeamType GetTeam() => _playerController?.GetTeam() ?? TeamType.Player; private void OnDrawGizmosSelected() {