Update
This commit is contained in:
37
Assets/Scripts/Network/PlayerDataManager.cs
Normal file
37
Assets/Scripts/Network/PlayerDataManager.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Fusion;
|
||||
using UnityEngine;
|
||||
|
||||
// struct quản lý thông tin
|
||||
public struct _PlayerMetaData : INetworkStruct
|
||||
{
|
||||
public NetworkString<_16> Name;
|
||||
public _Role Role;
|
||||
public NetworkBool IsReady;
|
||||
}
|
||||
|
||||
public class PlayerDataManager : NetworkBehaviour
|
||||
{
|
||||
[Networked]
|
||||
public NetworkDictionary<PlayerRef, _PlayerMetaData> Players => default;
|
||||
|
||||
[Rpc(RpcSources.All, RpcTargets.StateAuthority)]
|
||||
public void RPC_UpdatePlayerMetaData(PlayerRef playerRef, _PlayerMetaData metaData)
|
||||
{
|
||||
Players.Set(playerRef, metaData);
|
||||
}
|
||||
|
||||
[Rpc(RpcSources.All, RpcTargets.StateAuthority)]
|
||||
public void RPC_SetReady(PlayerRef playerRef, bool ready)
|
||||
{
|
||||
if (Players.TryGet(playerRef, out var data))
|
||||
{
|
||||
data.IsReady = ready;
|
||||
Players.Set(playerRef, data);
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryGetPlayerMetaData(PlayerRef playerRef, out _PlayerMetaData metaData)
|
||||
{
|
||||
return Players.TryGet(playerRef, out metaData);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user