네트워크 멀티플레이 환경 문제 수정

관련 문제가 다시 발생하면 이 커밋으로 돌아올 것
This commit is contained in:
2026-02-02 04:24:14 +09:00
parent 3e747a9d97
commit 10b496dfae
49 changed files with 2860 additions and 1792 deletions

View File

@@ -1,5 +1,6 @@
using Unity.Netcode;
using UnityEngine;
using System.Collections.Generic;
namespace Northbound
{
@@ -112,6 +113,7 @@ namespace Northbound
{
_currentResources.Value = maxResources;
_lastRechargeTime = Time.time;
_lastGatheringTime = Time.time - gatheringCooldown;
}
}
@@ -137,28 +139,17 @@ namespace Northbound
public bool CanInteract(ulong playerId)
{
// 자원 노드에 자원이 없으면 상호작용 불가
if (_currentResources.Value <= 0)
return false;
// 쿨다운 확인
if (Time.time - _lastGatheringTime < gatheringCooldown)
return false;
// 플레이어 인벤토리 확인
if (NetworkManager.Singleton != null &&
NetworkManager.Singleton.ConnectedClients.TryGetValue(playerId, out var client))
var resourceManager = ServerResourceManager.Instance;
if (resourceManager != null)
{
if (client.PlayerObject != null)
{
var playerInventory = client.PlayerObject.GetComponent<PlayerResourceInventory>();
if (playerInventory != null)
{
// 플레이어가 받을 수 있는 공간이 없으면 상호작용 불가
if (playerInventory.GetAvailableSpace() <= 0)
return false;
}
}
if (resourceManager.GetAvailableSpace(playerId) <= 0)
return false;
}
return true;
@@ -211,17 +202,11 @@ namespace Northbound
if (!CanInteract(playerId))
return;
var playerObject = NetworkManager.Singleton.ConnectedClients[playerId].PlayerObject;
if (playerObject == null)
var resourceManager = ServerResourceManager.Instance;
if (resourceManager == null)
return;
var playerInventory = playerObject.GetComponent<PlayerResourceInventory>();
if (playerInventory == null)
{
return;
}
int playerAvailableSpace = playerInventory.GetAvailableSpace();
int playerAvailableSpace = resourceManager.GetAvailableSpace(playerId);
int gatheredAmount = Mathf.Min(
resourcesPerGathering,
@@ -237,12 +222,27 @@ namespace Northbound
_currentResources.Value -= gatheredAmount;
_lastGatheringTime = Time.time;
playerInventory.AddResourceServerRpc(gatheredAmount);
resourceManager.AddResource(playerId, gatheredAmount);
UpdatePlayerResourcesClientRpc(playerId);
ShowGatheringEffectClientRpc();
}
[Rpc(SendTo.ClientsAndHost)]
private void UpdatePlayerResourcesClientRpc(ulong playerId)
{
var playerObject = NetworkManager.Singleton.ConnectedClients[playerId].PlayerObject;
if (playerObject != null)
{
var playerInventory = playerObject.GetComponent<PlayerResourceInventory>();
if (playerInventory != null)
{
playerInventory.RequestResourceUpdateServerRpc();
}
}
}
[Rpc(SendTo.NotServer)]
private void ShowGatheringEffectClientRpc()
{
if (gatheringEffectPrefab != null && effectSpawnPoint != null)
@@ -275,4 +275,4 @@ namespace Northbound
return transform;
}
}
}
}