45 lines
1.1 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using QSB.Messaging;
using QSB.TransformSync;
using UnityEngine;
using UnityEngine.Networking;
namespace QSB.Events
{
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)
{
PlayerRegistry.HandleFullStateMessage(message);
}
public void Send()
{
foreach (var player in PlayerRegistry.GetPlayers())
{
var message = new FullStateMessage()
{
PlayerName = player.Name,
SenderId = player.NetId
};
_messageHandler.SendToAll(message);
}
}
}
}