using Mirror; using QSB.WorldSync; namespace QSB.Messaging; public abstract class QSBWorldObjectMessage : QSBMessage where T : IWorldObject { /// /// set automatically by SendMessage /// internal int ObjectId; /// /// set automatically by ShouldReceive /// protected T WorldObject { get; private set; } public override void Serialize(NetworkWriter writer) { base.Serialize(writer); writer.Write(ObjectId); } public override void Deserialize(NetworkReader reader) { base.Deserialize(reader); ObjectId = reader.Read(); } public override bool ShouldReceive { get { if (!QSBWorldSync.AllObjectsReady) { return false; } WorldObject = ObjectId.GetWorldObject(); return true; } } } public abstract class QSBWorldObjectMessage : QSBWorldObjectMessage where T : IWorldObject { protected D Data { get; private set; } protected QSBWorldObjectMessage(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(); } }