2020-07-28 15:59:24 +02:00
|
|
|
|
using QSB.Messaging;
|
2020-05-19 19:31:54 +02:00
|
|
|
|
using UnityEngine.Networking;
|
|
|
|
|
|
|
|
|
|
namespace QSB.Events
|
|
|
|
|
{
|
2020-07-28 15:59:24 +02:00
|
|
|
|
public class GameState : NetworkBehaviour
|
2020-05-19 19:31:54 +02:00
|
|
|
|
{
|
2020-07-28 00:13:43 +01:00
|
|
|
|
public static GameState LocalInstance { get; private set; }
|
|
|
|
|
|
2020-05-19 19:31:54 +02:00
|
|
|
|
private MessageHandler<FullStateMessage> _messageHandler;
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
_messageHandler = new MessageHandler<FullStateMessage>();
|
|
|
|
|
_messageHandler.OnClientReceiveMessage += OnClientReceiveMessage;
|
2020-07-28 00:13:43 +01:00
|
|
|
|
|
|
|
|
|
LocalInstance = this;
|
2020-05-19 19:31:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnClientReceiveMessage(FullStateMessage message)
|
|
|
|
|
{
|
2020-07-28 00:13:43 +01:00
|
|
|
|
PlayerRegistry.HandleFullStateMessage(message);
|
2020-05-19 19:31:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Send()
|
|
|
|
|
{
|
2020-07-28 15:59:24 +02:00
|
|
|
|
foreach (var player in PlayerRegistry.PlayerList)
|
2020-05-19 19:31:54 +02:00
|
|
|
|
{
|
2020-07-28 15:59:24 +02:00
|
|
|
|
var message = new FullStateMessage
|
2020-07-28 00:13:43 +01:00
|
|
|
|
{
|
|
|
|
|
PlayerName = player.Name,
|
|
|
|
|
SenderId = player.NetId
|
|
|
|
|
};
|
2020-05-19 19:31:54 +02:00
|
|
|
|
|
2020-07-28 00:13:43 +01:00
|
|
|
|
_messageHandler.SendToAll(message);
|
|
|
|
|
}
|
2020-05-19 19:31:54 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|