1
Fork 0
mirror of https://github.com/Steffo99/better-tee.git synced 2024-11-23 07:44:19 +00:00
better-tee/Assets/Packages/Mirror/Runtime/NetworkMessage.cs

26 lines
768 B
C#
Raw Normal View History

2019-09-17 15:43:32 +00:00
namespace Mirror
{
public struct NetworkMessage
{
public int msgType;
public NetworkConnection conn;
public NetworkReader reader;
public TMsg ReadMessage<TMsg>() where TMsg : IMessageBase, new()
{
// Normally I would just do:
// TMsg msg = new TMsg();
// but mono calls an expensive method Activator.CreateInstance
// For value types this is unnecesary, just use the default value
TMsg msg = typeof(TMsg).IsValueType ? default(TMsg) : new TMsg();
msg.Deserialize(reader);
return msg;
}
public void ReadMessage<TMsg>(TMsg msg) where TMsg : IMessageBase
{
msg.Deserialize(reader);
}
}
}