Ricardo Lopes 83e8112c0a
Sync game state on connect (#86)
* Sync full state on init

* Sync game state on start
2020-05-19 19:31:54 +02:00

36 lines
876 B
C#

using System.Collections;
using System.Collections.Generic;
using QSB.Messaging;
using QSB.TransformSync;
using UnityEngine;
using UnityEngine.Networking;
namespace QSB.Events
{
class GameState : NetworkBehaviour
{
private MessageHandler<FullStateMessage> _messageHandler;
private void Awake()
{
_messageHandler = new MessageHandler<FullStateMessage>();
_messageHandler.OnClientReceiveMessage += OnClientReceiveMessage;
}
private void OnClientReceiveMessage(FullStateMessage message)
{
PlayerJoin.PlayerNames = message.PlayerNames;
}
public void Send()
{
var message = new FullStateMessage()
{
PlayerNames = PlayerJoin.PlayerNames
};
_messageHandler.SendToAll(message);
}
}
}