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