quantum-space-buddies/QSB/TimeSync/Messages/ServerTimeMessage.cs

38 lines
884 B
C#
Raw Permalink Normal View History

using Mirror;
using QSB.Messaging;
2022-03-03 03:46:33 +00:00
namespace QSB.TimeSync.Messages;
2021-12-23 05:06:58 +00:00
2022-03-03 03:46:33 +00:00
public class ServerTimeMessage : QSBMessage
{
private float ServerTime;
private int LoopCount;
2022-08-14 23:35:19 +00:00
private float SecondsRemaining;
2021-12-23 05:06:58 +00:00
2022-08-14 23:35:19 +00:00
public ServerTimeMessage(float time, int count, float secondsRemaining)
2022-03-03 03:46:33 +00:00
{
ServerTime = time;
LoopCount = count;
2022-08-14 23:35:19 +00:00
SecondsRemaining = secondsRemaining;
2022-03-03 03:46:33 +00:00
}
2022-03-03 03:46:33 +00:00
public override void Serialize(NetworkWriter writer)
{
base.Serialize(writer);
writer.Write(ServerTime);
writer.Write(LoopCount);
2022-08-14 23:35:19 +00:00
writer.Write(SecondsRemaining);
2022-03-03 03:46:33 +00:00
}
2022-03-03 03:46:33 +00:00
public override void Deserialize(NetworkReader reader)
{
base.Deserialize(reader);
ServerTime = reader.Read<float>();
LoopCount = reader.Read<int>();
2022-08-14 23:35:19 +00:00
SecondsRemaining = reader.Read<float>();
}
2022-03-03 03:46:33 +00:00
public override void OnReceiveRemote()
2023-03-09 16:38:17 +00:00
=> WakeUpSync.LocalInstance?.OnClientReceiveMessage(ServerTime, LoopCount, SecondsRemaining);
2022-08-14 23:35:19 +00:00
}