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