mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 19:10:32 +00:00
65d81d6fb4
* Transports now give the channel when receiving message * Profile inbound messages channel id
27 lines
798 B
C#
27 lines
798 B
C#
namespace Mirror
|
|
{
|
|
public struct NetworkMessage
|
|
{
|
|
public int msgType;
|
|
public NetworkConnection conn;
|
|
public NetworkReader reader;
|
|
public int channelId;
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|