Mister_Nebula 1effae0bd3 event overhaul
i have no idea how i did this but it works
2020-08-08 00:08:44 +01:00

44 lines
1.3 KiB
C#

using QSB.Messaging;
using QSB.Utility;
using UnityEngine.Networking;
namespace QSB.Events
{
public class GameState : NetworkBehaviour
{
public static GameState LocalInstance { get; private set; }
private MessageHandler<FullStateMessage> _messageHandler;
private void Awake()
{
_messageHandler = new MessageHandler<FullStateMessage>();
_messageHandler.OnClientReceiveMessage += OnClientReceiveMessage;
LocalInstance = this;
}
private void OnClientReceiveMessage(FullStateMessage message)
{
DebugLog.ToConsole($"Received game state id {PlayerRegistry.LocalPlayer.NetId}");
PlayerRegistry.HandleFullStateMessage(message);
}
public void Send()
{
DebugLog.ToConsole("Sending game state to all players.");
foreach (var player in PlayerRegistry.PlayerList)
{
var message = new FullStateMessage
{
PlayerName = player.Name,
SenderId = player.NetId
};
_messageHandler.SendToAll(message);
DebugLog.ToConsole($"* Sent state for {player.NetId}");
}
}
}
}