2022-01-14 04:52:04 +00:00
|
|
|
|
using Mirror;
|
2021-12-11 07:28:42 +00:00
|
|
|
|
|
|
|
|
|
namespace QSB.Messaging
|
|
|
|
|
{
|
2022-01-14 10:29:42 +00:00
|
|
|
|
public abstract class QSBMessage
|
2021-12-11 07:28:42 +00:00
|
|
|
|
{
|
2021-12-24 00:08:02 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// set automatically by Send
|
|
|
|
|
/// </summary>
|
2021-12-23 01:13:54 +00:00
|
|
|
|
internal uint From;
|
2021-12-11 08:46:55 +00:00
|
|
|
|
/// <summary>
|
2021-12-22 09:16:44 +00:00
|
|
|
|
/// (default) uint.MaxValue = send to everyone <br/>
|
2021-12-11 08:46:55 +00:00
|
|
|
|
/// 0 = send to host
|
|
|
|
|
/// </summary>
|
2021-12-11 08:06:09 +00:00
|
|
|
|
public uint To = uint.MaxValue;
|
2021-12-11 07:28:42 +00:00
|
|
|
|
|
2021-12-24 00:53:22 +00:00
|
|
|
|
/// <summary>
|
2021-12-11 08:46:55 +00:00
|
|
|
|
/// call the base method when overriding
|
2021-12-24 00:53:22 +00:00
|
|
|
|
/// </summary>
|
2022-01-14 07:38:45 +00:00
|
|
|
|
public virtual void Serialize(NetworkWriter writer)
|
2021-12-11 07:28:42 +00:00
|
|
|
|
{
|
|
|
|
|
writer.Write(From);
|
|
|
|
|
writer.Write(To);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-24 00:53:22 +00:00
|
|
|
|
/// <summary>
|
2021-12-11 08:46:55 +00:00
|
|
|
|
/// call the base method when overriding
|
2021-12-27 02:57:49 +00:00
|
|
|
|
/// <para/>
|
|
|
|
|
/// note: no constructor is called before this,
|
|
|
|
|
/// so fields won't be initialized.
|
2021-12-24 00:53:22 +00:00
|
|
|
|
/// </summary>
|
2022-01-14 07:38:45 +00:00
|
|
|
|
public virtual void Deserialize(NetworkReader reader)
|
2021-12-11 07:28:42 +00:00
|
|
|
|
{
|
2022-01-14 07:38:45 +00:00
|
|
|
|
From = reader.Read<uint>();
|
|
|
|
|
To = reader.Read<uint>();
|
2021-12-11 07:28:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-24 00:53:22 +00:00
|
|
|
|
/// <summary>
|
2021-12-21 00:35:12 +00:00
|
|
|
|
/// checked before calling either OnReceive
|
2021-12-24 00:53:22 +00:00
|
|
|
|
/// </summary>
|
2021-12-21 20:38:43 +00:00
|
|
|
|
public virtual bool ShouldReceive => true;
|
|
|
|
|
public virtual void OnReceiveLocal() { }
|
2021-12-27 04:12:50 +00:00
|
|
|
|
public virtual void OnReceiveRemote() { }
|
2021-12-26 12:36:00 +00:00
|
|
|
|
|
|
|
|
|
public override string ToString() => GetType().Name;
|
2021-12-11 07:28:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 04:28:59 +00:00
|
|
|
|
public abstract class QSBMessage<V> : QSBMessage
|
2021-12-11 07:28:42 +00:00
|
|
|
|
{
|
2022-01-27 04:28:59 +00:00
|
|
|
|
protected V Value;
|
2021-12-11 07:28:42 +00:00
|
|
|
|
|
2022-01-14 07:38:45 +00:00
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
2021-12-11 07:28:42 +00:00
|
|
|
|
{
|
|
|
|
|
base.Serialize(writer);
|
|
|
|
|
writer.Write(Value);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-14 07:38:45 +00:00
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
2021-12-11 07:28:42 +00:00
|
|
|
|
{
|
|
|
|
|
base.Deserialize(reader);
|
2022-01-27 04:28:59 +00:00
|
|
|
|
Value = reader.Read<V>();
|
2021-12-11 07:28:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|