모든 네트워크 오브젝트의 소유권을 서버가 갖도록 함
Distributable -> None 관련 사이드 이펙트로 인한 버그 수정
This commit is contained in:
@@ -11,32 +11,65 @@ namespace Northbound
|
||||
public int CurrentResourceAmount => _displayAmount;
|
||||
public int MaxResourceCapacity => maxResourceCapacity;
|
||||
|
||||
private NetworkPlayerController _networkPlayerController;
|
||||
|
||||
private bool IsLocalPlayer => _networkPlayerController != null && _networkPlayerController.IsLocalPlayer;
|
||||
private ulong LocalPlayerId => _networkPlayerController != null ? _networkPlayerController.OwnerPlayerId : OwnerClientId;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_networkPlayerController = GetComponent<NetworkPlayerController>();
|
||||
}
|
||||
|
||||
[Rpc(SendTo.Server)]
|
||||
private void SetMaxCapacityServerRpc(int maxCapacity)
|
||||
private void SetMaxCapacityServerRpc(int maxCapacity, ulong playerId)
|
||||
{
|
||||
var resourceManager = ServerResourceManager.Instance;
|
||||
if (resourceManager != null)
|
||||
{
|
||||
resourceManager.SetPlayerMaxCapacity(OwnerClientId, maxCapacity);
|
||||
resourceManager.SetPlayerMaxCapacity(playerId, maxCapacity);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnNetworkSpawn()
|
||||
{
|
||||
if (IsClient && IsOwner)
|
||||
// _ownerPlayerId 변경 이벤트 구독
|
||||
if (_networkPlayerController != null)
|
||||
{
|
||||
SetMaxCapacityServerRpc(maxResourceCapacity);
|
||||
RequestResourceUpdateServerRpc();
|
||||
_networkPlayerController.OnOwnerChanged += OnOwnerPlayerIdChanged;
|
||||
}
|
||||
|
||||
TryInitialize();
|
||||
}
|
||||
|
||||
private void OnOwnerPlayerIdChanged(ulong newOwnerId)
|
||||
{
|
||||
TryInitialize();
|
||||
}
|
||||
|
||||
private void TryInitialize()
|
||||
{
|
||||
if (!IsLocalPlayer) return;
|
||||
|
||||
SetMaxCapacityServerRpc(maxResourceCapacity, LocalPlayerId);
|
||||
RequestResourceUpdateServerRpc(LocalPlayerId);
|
||||
}
|
||||
|
||||
public override void OnNetworkDespawn()
|
||||
{
|
||||
if (_networkPlayerController != null)
|
||||
{
|
||||
_networkPlayerController.OnOwnerChanged -= OnOwnerPlayerIdChanged;
|
||||
}
|
||||
}
|
||||
|
||||
[Rpc(SendTo.Server)]
|
||||
public void RequestResourceUpdateServerRpc()
|
||||
public void RequestResourceUpdateServerRpc(ulong playerId)
|
||||
{
|
||||
var resourceManager = ServerResourceManager.Instance;
|
||||
if (resourceManager != null)
|
||||
{
|
||||
int amount = resourceManager.GetPlayerResourceAmount(OwnerClientId);
|
||||
int amount = resourceManager.GetPlayerResourceAmount(playerId);
|
||||
UpdateResourceAmountClientRpc(amount);
|
||||
}
|
||||
}
|
||||
@@ -57,7 +90,7 @@ namespace Northbound
|
||||
var resourceManager = ServerResourceManager.Instance;
|
||||
if (resourceManager != null)
|
||||
{
|
||||
return resourceManager.CanAddResource(OwnerClientId, amount);
|
||||
return resourceManager.CanAddResource(LocalPlayerId, amount);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -67,7 +100,7 @@ namespace Northbound
|
||||
var resourceManager = ServerResourceManager.Instance;
|
||||
if (resourceManager != null)
|
||||
{
|
||||
return resourceManager.GetAvailableSpace(OwnerClientId);
|
||||
return resourceManager.GetAvailableSpace(LocalPlayerId);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user