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