2022-01-13 23:38:45 -08:00
|
|
|
|
using Mirror;
|
|
|
|
|
using QSB.WorldSync;
|
2021-12-23 17:07:29 -08:00
|
|
|
|
using System;
|
2021-12-10 23:28:42 -08:00
|
|
|
|
|
|
|
|
|
namespace QSB.Messaging
|
|
|
|
|
{
|
|
|
|
|
public abstract class QSBWorldObjectMessage<T> : QSBMessage where T : IWorldObject
|
|
|
|
|
{
|
2021-12-23 16:08:02 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// set automatically by SendMessage
|
|
|
|
|
/// </summary>
|
2021-12-22 17:13:54 -08:00
|
|
|
|
internal int ObjectId;
|
2021-12-23 16:08:02 -08:00
|
|
|
|
/// <summary>
|
2021-12-25 23:48:32 -08:00
|
|
|
|
/// set automatically by ShouldReceive
|
2021-12-23 16:08:02 -08:00
|
|
|
|
/// </summary>
|
2021-12-23 15:46:18 -08:00
|
|
|
|
protected T WorldObject { get; private set; }
|
2021-12-10 23:28:42 -08:00
|
|
|
|
|
2022-01-13 23:38:45 -08:00
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
2021-12-10 23:28:42 -08:00
|
|
|
|
{
|
|
|
|
|
base.Serialize(writer);
|
|
|
|
|
writer.Write(ObjectId);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-13 23:38:45 -08:00
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
2021-12-10 23:28:42 -08:00
|
|
|
|
{
|
|
|
|
|
base.Deserialize(reader);
|
2022-01-13 23:38:45 -08:00
|
|
|
|
ObjectId = reader.Read<int>();
|
2021-12-10 23:28:42 -08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-21 12:38:43 -08:00
|
|
|
|
public override bool ShouldReceive
|
2021-12-10 23:28:42 -08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2022-01-18 00:27:32 -08:00
|
|
|
|
if (!QSBWorldSync.AllObjectsReady)
|
2021-12-10 23:28:42 -08:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 22:37:20 -08:00
|
|
|
|
WorldObject = ObjectId.GetWorldObject<T>();
|
2021-12-10 23:28:42 -08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class QSBBoolWorldObjectMessage<T> : QSBWorldObjectMessage<T> where T : IWorldObject
|
|
|
|
|
{
|
2021-12-22 17:13:54 -08:00
|
|
|
|
protected bool Value;
|
2021-12-10 23:28:42 -08:00
|
|
|
|
|
2022-01-13 23:38:45 -08:00
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
2021-12-10 23:28:42 -08:00
|
|
|
|
{
|
|
|
|
|
base.Serialize(writer);
|
|
|
|
|
writer.Write(Value);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-13 23:38:45 -08:00
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
2021-12-10 23:28:42 -08:00
|
|
|
|
{
|
|
|
|
|
base.Deserialize(reader);
|
2022-01-13 23:38:45 -08:00
|
|
|
|
Value = reader.Read<bool>();
|
2021-12-10 23:28:42 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class QSBFloatWorldObjectMessage<T> : QSBWorldObjectMessage<T> where T : IWorldObject
|
|
|
|
|
{
|
2021-12-22 17:13:54 -08:00
|
|
|
|
protected float Value;
|
2021-12-10 23:28:42 -08:00
|
|
|
|
|
2022-01-13 23:38:45 -08:00
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
2021-12-10 23:28:42 -08:00
|
|
|
|
{
|
|
|
|
|
base.Serialize(writer);
|
|
|
|
|
writer.Write(Value);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-13 23:38:45 -08:00
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
2021-12-10 23:28:42 -08:00
|
|
|
|
{
|
|
|
|
|
base.Deserialize(reader);
|
2022-01-13 23:38:45 -08:00
|
|
|
|
Value = reader.Read<float>();
|
2021-12-10 23:28:42 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class QSBEnumWorldObjectMessage<T, E> : QSBWorldObjectMessage<T>
|
|
|
|
|
where T : IWorldObject
|
|
|
|
|
where E : Enum
|
|
|
|
|
{
|
2021-12-22 17:13:54 -08:00
|
|
|
|
protected E Value;
|
2021-12-10 23:28:42 -08:00
|
|
|
|
|
2022-01-13 23:38:45 -08:00
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
2021-12-10 23:28:42 -08:00
|
|
|
|
{
|
|
|
|
|
base.Serialize(writer);
|
|
|
|
|
writer.Write((int)(object)Value);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-13 23:38:45 -08:00
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
2021-12-10 23:28:42 -08:00
|
|
|
|
{
|
|
|
|
|
base.Deserialize(reader);
|
2022-01-13 23:38:45 -08:00
|
|
|
|
Value = (E)(object)reader.Read<int>();
|
2021-12-10 23:28:42 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|