mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-18 04:10:36 +00:00
48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using QSB.Messaging;
|
|
using UnityEngine.Networking;
|
|
|
|
namespace QSB.Events
|
|
{
|
|
public class PlayerState : NetworkBehaviour
|
|
{
|
|
public static PlayerState LocalInstance { get; private set; }
|
|
|
|
private MessageHandler<PlayerStateMessage> _messageHandler;
|
|
|
|
private void Awake()
|
|
{
|
|
_messageHandler = new MessageHandler<PlayerStateMessage>(EventType.FullState);
|
|
_messageHandler.OnClientReceiveMessage += OnClientReceiveMessage;
|
|
|
|
LocalInstance = this;
|
|
}
|
|
|
|
private void OnClientReceiveMessage(PlayerStateMessage message)
|
|
{
|
|
if (message.AboutId == PlayerRegistry.LocalPlayerId)
|
|
{
|
|
return;
|
|
}
|
|
QSB.Helper.Events.Unity.RunWhen(
|
|
() => PlayerRegistry.GetSyncObject<TransformSync.TransformSync>(message.AboutId) != null,
|
|
() => PlayerRegistry.HandleFullStateMessage(message));
|
|
}
|
|
|
|
public void Send()
|
|
{
|
|
foreach (var player in PlayerRegistry.PlayerList)
|
|
{
|
|
var message = new PlayerStateMessage
|
|
{
|
|
AboutId = player.PlayerId,
|
|
PlayerName = player.Name,
|
|
PlayerReady = player.IsReady,
|
|
PlayerState = player.State
|
|
};
|
|
|
|
_messageHandler.SendToAll(message);
|
|
}
|
|
}
|
|
}
|
|
}
|