/// <summary> /// 接收消息回调函数 /// </summary> private void OnHandleHotfixMsg(INetworkPackage pack) { DefaultNetworkPackage package = pack as DefaultNetworkPackage; Type msgType = _types.GetValueByKey(package.MsgID); HotfixLogger.Log($"Handle hotfix net message : {msgType}"); object instance = Activator.CreateInstance(msgType); var message = ProtobufHelper.Decode(instance, package.BodyBytes); HotfixLogger.Log(message.ToString()); }
/// <summary> /// 接收消息回调函数 /// </summary> private void OnHandleHotfixMsg(NetReceivePackage package) { Type msgType = _msgTypes.GetValueByKey(package.Type); object instance = Activator.CreateInstance(msgType); var message = ProtobufHelper.Decode(instance, package.ProtoBodyData); Debug.Log($"Handle net message : {package.Type}"); // TODO 可以在这里分发消息到逻辑层 R2C_Login loginMsg = message as R2C_Login; if (loginMsg != null) { Debug.Log($"R2C_Login = {loginMsg.Address}"); Debug.Log($"R2C_Login = {loginMsg.Key}"); } }
protected override object DecodeInternal(Type classType, byte[] bodyBytes) { return(ProtobufHelper.Decode(classType, bodyBytes)); }