자원 채집 및 반환 기능
텍스트 기능 및 폰트 추가
This commit is contained in:
76
Assets/Scripts/PlayerResourceInventory.cs
Normal file
76
Assets/Scripts/PlayerResourceInventory.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Northbound
|
||||
{
|
||||
/// <summary>
|
||||
/// 플레이어의 자원 인벤토리 관리
|
||||
/// </summary>
|
||||
public class PlayerResourceInventory : NetworkBehaviour
|
||||
{
|
||||
[Header("Inventory Settings")]
|
||||
public int maxResourceCapacity = 100; // 최대 자원 보유량
|
||||
|
||||
private NetworkVariable<int> _currentResourceAmount = new NetworkVariable<int>(
|
||||
0,
|
||||
NetworkVariableReadPermission.Everyone,
|
||||
NetworkVariableWritePermission.Server
|
||||
);
|
||||
|
||||
public int CurrentResourceAmount => _currentResourceAmount.Value;
|
||||
public int MaxResourceCapacity => maxResourceCapacity;
|
||||
|
||||
/// <summary>
|
||||
/// 자원을 추가할 수 있는지 확인
|
||||
/// </summary>
|
||||
public bool CanAddResource(int amount)
|
||||
{
|
||||
return _currentResourceAmount.Value + amount <= maxResourceCapacity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 추가 가능한 최대 자원량 계산
|
||||
/// </summary>
|
||||
public int GetAvailableSpace()
|
||||
{
|
||||
return maxResourceCapacity - _currentResourceAmount.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 자원 추가 (서버에서만 호출)
|
||||
/// </summary>
|
||||
[Rpc(SendTo.Server, InvokePermission = RpcInvokePermission.Everyone)]
|
||||
public void AddResourceServerRpc(int amount)
|
||||
{
|
||||
if (amount <= 0) return;
|
||||
|
||||
int actualAmount = Mathf.Min(amount, maxResourceCapacity - _currentResourceAmount.Value);
|
||||
_currentResourceAmount.Value += actualAmount;
|
||||
|
||||
Debug.Log($"플레이어 {OwnerClientId} - 자원 추가: +{actualAmount}, 현재: {_currentResourceAmount.Value}/{maxResourceCapacity}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 자원 제거 (서버에서만 호출)
|
||||
/// </summary>
|
||||
[Rpc(SendTo.Server, InvokePermission = RpcInvokePermission.Everyone)]
|
||||
public void RemoveResourceServerRpc(int amount)
|
||||
{
|
||||
if (amount <= 0) return;
|
||||
|
||||
int actualAmount = Mathf.Min(amount, _currentResourceAmount.Value);
|
||||
_currentResourceAmount.Value -= actualAmount;
|
||||
|
||||
Debug.Log($"플레이어 {OwnerClientId} - 자원 사용: -{actualAmount}, 현재: {_currentResourceAmount.Value}/{maxResourceCapacity}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 자원 설정 (서버에서만 호출)
|
||||
/// </summary>
|
||||
[Rpc(SendTo.Server, InvokePermission = RpcInvokePermission.Everyone)]
|
||||
public void SetResourceServerRpc(int amount)
|
||||
{
|
||||
_currentResourceAmount.Value = Mathf.Clamp(amount, 0, maxResourceCapacity);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user