using Mirror; namespace QSB.Messaging; public abstract class QSBMessage { /// /// set automatically by Send /// // public so it can be accessed by a patch public uint From; /// /// (default) uint.MaxValue = send to everyone
/// 0 = send to host ///
public uint To = uint.MaxValue; /// /// call the base method when overriding /// public virtual void Serialize(NetworkWriter writer) { writer.Write(From); writer.Write(To); } /// /// call the base method when overriding /// /// note: no constructor is called before this, /// so fields won't be initialized. /// public virtual void Deserialize(NetworkReader reader) { From = reader.Read(); To = reader.Read(); } /// /// checked before calling either OnReceive /// public virtual bool ShouldReceive => true; public virtual void OnReceiveLocal() { } public virtual void OnReceiveRemote() { } } public abstract class QSBMessage : QSBMessage { // public so it can be accessed by a patch public D Data { get; private set; } protected QSBMessage(D data) => Data = data; public override void Serialize(NetworkWriter writer) { base.Serialize(writer); writer.Write(Data); } public override void Deserialize(NetworkReader reader) { base.Deserialize(reader); Data = reader.Read(); } }