mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
fix: pack works if message is boxed
This commit is contained in:
parent
6dcea5ffd5
commit
55c9bb625a
@ -25,6 +25,11 @@ public static int GetId<T>() where T : IMessageBase
|
||||
return typeof(T).FullName.GetStableHashCode() & 0xFFFF;
|
||||
}
|
||||
|
||||
public static int GetId(Type type)
|
||||
{
|
||||
return type.FullName.GetStableHashCode() & 0xFFFF;
|
||||
}
|
||||
|
||||
// pack message before sending
|
||||
[EditorBrowsable(EditorBrowsableState.Never), Obsolete("Use Pack<T> instead")]
|
||||
public static byte[] PackMessage(int msgType, MessageBase msg)
|
||||
@ -54,7 +59,7 @@ public static byte[] Pack<T>(T message) where T : IMessageBase
|
||||
try
|
||||
{
|
||||
// write message type
|
||||
int msgType = GetId<T>();
|
||||
int msgType = GetId(message.GetType());
|
||||
writer.WriteUInt16((ushort)msgType);
|
||||
|
||||
// serialize message into writer
|
||||
|
@ -334,7 +334,7 @@ internal bool InvokeHandler(int msgType, NetworkReader reader)
|
||||
/// <returns></returns>
|
||||
public bool InvokeHandler<T>(T msg) where T : IMessageBase
|
||||
{
|
||||
int msgType = MessagePacker.GetId<T>();
|
||||
int msgType = MessagePacker.GetId(msg.GetType());
|
||||
byte[] data = MessagePacker.Pack(msg);
|
||||
return InvokeHandler(msgType, new NetworkReader(data));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user