/// <summary> /// 发送网络消息 /// </summary> public void SendHotfixMsg(IHotfixNetMessage msg) { HotfixLog.Log($"Send hotfix net message : {msg.GetType()}"); int msgID = _types.GetKeyByValue(msg.GetType()); DefaultNetworkPackage package = new DefaultNetworkPackage(); package.MsgID = msgID; package.BodyBytes = ProtobufHelper.Encode(msg); NetworkManager.Instance.SendMessage(package); }
public static void Serialize(BufferWriter writer, object command) { Type tmpCommandType = command.GetType(); ushort tmpOpcode = sCommandOpcode2TypeDict.GetKeyByValue(tmpCommandType); writer.Write((byte)(tmpOpcode >> 8)); writer.Write((byte)(tmpOpcode & 0xff)); FieldInfo tmpFieldInfo = null; if (!sCommandType2FieldInfoDict.TryGetValue(tmpCommandType, out tmpFieldInfo)) { return; } IMessage tmpProtoMsg = tmpFieldInfo.GetValue(command) as IMessage; if (null == tmpProtoMsg) { return; } tmpProtoMsg.WriteTo(writer.stream); }
/// <summary> /// 发送网络消息 /// </summary> public void SendMsg(IHotfixMessage msg) { ushort msgID = _msgTypes.GetKeyByValue(msg.GetType()); NetManager.Instance.SendMsg(msgID, msg); }