using Mirror; using QSB.WorldSync; using System; 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 QSBBoolWorldObjectMessage : QSBWorldObjectMessage where T : IWorldObject { protected bool Value; public override void Serialize(NetworkWriter writer) { base.Serialize(writer); writer.Write(Value); } public override void Deserialize(NetworkReader reader) { base.Deserialize(reader); Value = reader.Read(); } } public abstract class QSBFloatWorldObjectMessage : QSBWorldObjectMessage where T : IWorldObject { protected float Value; public override void Serialize(NetworkWriter writer) { base.Serialize(writer); writer.Write(Value); } public override void Deserialize(NetworkReader reader) { base.Deserialize(reader); Value = reader.Read(); } } public abstract class QSBEnumWorldObjectMessage : QSBWorldObjectMessage where T : IWorldObject where E : Enum { protected E Value; public override void Serialize(NetworkWriter writer) { base.Serialize(writer); writer.Write((int)(object)Value); } public override void Deserialize(NetworkReader reader) { base.Deserialize(reader); Value = (E)(object)reader.Read(); } } }