네트워크 멀티플레이 대응

This commit is contained in:
2026-01-31 20:49:23 +09:00
parent 1152093521
commit c5bcf265d0
69 changed files with 2766 additions and 1392 deletions

View File

@@ -0,0 +1,73 @@
using Unity.Netcode;
using UnityEngine;
namespace Northbound
{
public class PlayerInventory : NetworkBehaviour
{
[Header("Inventory Settings")]
public int maxResourceCapacity = 100;
private NetworkVariable<int> resourceCount = new NetworkVariable<int>(
0,
NetworkVariableReadPermission.Everyone,
NetworkVariableWritePermission.Owner
);
public int CurrentResourceAmount => resourceCount.Value;
public int MaxResourceCapacity => maxResourceCapacity;
public bool CanAddResource(int amount)
{
return resourceCount.Value + amount <= maxResourceCapacity;
}
public int GetAvailableSpace()
{
return maxResourceCapacity - resourceCount.Value;
}
public void AddResources(int amount)
{
if (amount <= 0) return;
int actualAmount = Mathf.Min(amount, maxResourceCapacity - resourceCount.Value);
resourceCount.Value += actualAmount;
Debug.Log($"Player {OwnerClientId} added resources: +{actualAmount}, total: {resourceCount.Value}/{maxResourceCapacity}");
}
public void RemoveResources(int amount)
{
if (amount <= 0) return;
int actualAmount = Mathf.Min(amount, resourceCount.Value);
resourceCount.Value -= actualAmount;
Debug.Log($"Player {OwnerClientId} used resources: -{actualAmount}, total: {resourceCount.Value}/{maxResourceCapacity}");
}
public void SetResources(int amount)
{
resourceCount.Value = Mathf.Clamp(amount, 0, maxResourceCapacity);
}
[Rpc(SendTo.Owner)]
public void AddResourcesRpc(int amount)
{
AddResources(amount);
}
[Rpc(SendTo.Owner)]
public void RemoveResourcesRpc(int amount)
{
RemoveResources(amount);
}
[Rpc(SendTo.Owner)]
public void SetResourcesRpc(int amount)
{
SetResources(amount);
}
}
}