2022-01-14 07:38:45 +00:00
|
|
|
|
using Mirror;
|
|
|
|
|
using QSB.WorldSync;
|
2021-12-11 07:28:42 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace QSB.Messaging;
|
|
|
|
|
|
|
|
|
|
public abstract class QSBWorldObjectMessage<T> : QSBMessage where T : IWorldObject
|
2021-12-11 07:28:42 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// set automatically by SendMessage
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal int ObjectId;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// set automatically by ShouldReceive
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected T WorldObject { get; private set; }
|
|
|
|
|
|
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
2021-12-11 07:28:42 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
base.Serialize(writer);
|
|
|
|
|
writer.Write(ObjectId);
|
|
|
|
|
}
|
2021-12-11 07:28:42 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
|
{
|
|
|
|
|
base.Deserialize(reader);
|
|
|
|
|
ObjectId = reader.Read<int>();
|
|
|
|
|
}
|
2021-12-11 07:28:42 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override bool ShouldReceive
|
|
|
|
|
{
|
|
|
|
|
get
|
2021-12-11 07:28:42 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
if (!QSBWorldSync.AllObjectsReady)
|
2021-12-11 07:28:42 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
return false;
|
2022-02-27 12:40:44 +00:00
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
|
|
|
|
|
WorldObject = ObjectId.GetWorldObject<T>();
|
|
|
|
|
return true;
|
2021-12-11 07:28:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
}
|
2021-12-11 07:28:42 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public abstract class QSBWorldObjectMessage<T, D> : QSBWorldObjectMessage<T> where T : IWorldObject
|
|
|
|
|
{
|
2022-03-11 01:39:00 +00:00
|
|
|
|
protected D Data { get; private set; }
|
2022-03-11 01:28:52 +00:00
|
|
|
|
protected QSBWorldObjectMessage(D data) => Data = data;
|
2021-12-11 07:28:42 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
|
|
|
{
|
|
|
|
|
base.Serialize(writer);
|
|
|
|
|
writer.Write(Data);
|
|
|
|
|
}
|
2022-02-27 12:40:44 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
|
|
|
{
|
|
|
|
|
base.Deserialize(reader);
|
|
|
|
|
Data = reader.Read<D>();
|
2021-12-11 07:28:42 +00:00
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
}
|