quantum-space-buddies/QSB/Messaging/QSBWorldObjectMessage.cs

61 lines
1.2 KiB
C#
Raw Normal View History

using Mirror;
using QSB.WorldSync;
namespace QSB.Messaging
{
public abstract class QSBWorldObjectMessage<T> : QSBMessage where T : IWorldObject
{
/// <summary>
/// set automatically by SendMessage
/// </summary>
2021-12-23 01:13:54 +00:00
internal int ObjectId;
/// <summary>
2021-12-26 07:48:32 +00:00
/// set automatically by ShouldReceive
/// </summary>
2021-12-23 23:46:18 +00:00
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<int>();
}
2021-12-21 20:38:43 +00:00
public override bool ShouldReceive
{
get
{
if (!QSBWorldSync.AllObjectsReady)
{
return false;
}
WorldObject = ObjectId.GetWorldObject<T>();
return true;
}
}
}
2022-01-27 04:28:59 +00:00
public abstract class QSBWorldObjectMessage<T, V> : QSBWorldObjectMessage<T> where T : IWorldObject
{
2022-01-27 04:28:59 +00:00
protected V Value;
public override void Serialize(NetworkWriter writer)
{
base.Serialize(writer);
writer.Write(Value);
}
public override void Deserialize(NetworkReader reader)
{
base.Deserialize(reader);
2022-01-27 04:28:59 +00:00
Value = reader.Read<V>();
}
}
}