2020-07-28 00:13:43 +01:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
using QSB.TransformSync;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.Networking;
|
|
|
|
|
|
|
|
|
|
namespace QSB.Events
|
|
|
|
|
{
|
|
|
|
|
public class FullStateRequest : NetworkBehaviour
|
|
|
|
|
{
|
2020-08-07 23:18:07 +02:00
|
|
|
|
public static FullStateRequest Instance { get; private set; }
|
2020-07-28 00:13:43 +01:00
|
|
|
|
|
|
|
|
|
private MessageHandler<StateRequestMessage> _stateRequestHandler;
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
2020-08-07 23:18:07 +02:00
|
|
|
|
Instance = this;
|
|
|
|
|
|
2020-08-09 11:11:45 +02:00
|
|
|
|
_stateRequestHandler = new MessageHandler<StateRequestMessage>(MessageType.FullStateRequest);
|
2020-07-28 00:13:43 +01:00
|
|
|
|
_stateRequestHandler.OnServerReceiveMessage += OnServerReceiveMessage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Request()
|
|
|
|
|
{
|
|
|
|
|
StartCoroutine(SendRequest());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerator SendRequest()
|
|
|
|
|
{
|
|
|
|
|
yield return new WaitUntil(() => PlayerTransformSync.LocalInstance != null);
|
|
|
|
|
var message = new StateRequestMessage
|
|
|
|
|
{
|
|
|
|
|
SenderId = PlayerTransformSync.LocalInstance.netId.Value
|
|
|
|
|
};
|
|
|
|
|
_stateRequestHandler.SendToServer(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnServerReceiveMessage(StateRequestMessage message)
|
|
|
|
|
{
|
|
|
|
|
GameState.LocalInstance.Send();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|