/// <summary> /// 接口实现 /// 解析消息基类XML /// </summary> public void ParserXml(string filePath, bool isOneFile = false) { XmlDocument doc = new XmlDocument(); doc.Load(filePath); AllBaseCmdFileData targetFileData = new AllBaseCmdFileData(); //文件名 XmlNode fileNameNode = doc.SelectSingleNode(NetCmdXmlParser.fileNameNodeStr); targetFileData.mClassName = fileNameNode.InnerText; //文件描述 XmlNode commentNode = doc.SelectSingleNode(baseCmdDesNodeStr); targetFileData.mDescribe = commentNode.InnerText; //父类 XmlNode fatherNode = doc.SelectSingleNode(baseCmdFatherNodeStr); targetFileData.mFatherName = fatherNode.InnerText; //协议消息名 XmlNode gscmd = doc.SelectSingleNode(baseCmdGscmdNodeStr); targetFileData.mGsCmd = gscmd.InnerText; //消息值 XmlNode num = doc.SelectSingleNode(baseCmdNumNodeStr); targetFileData.mNum = num.InnerText; //是否导出C# XmlNode isCS = doc.SelectSingleNode(baseCmdIsNeedCNodeStr); if (isCS == null) { targetFileData.mIsCS = true; } else { targetFileData.mIsCS = isCS.InnerText == "true" ? true : false; } //是否导出C# XmlNode isLua = doc.SelectSingleNode(baseCmdIsNeedLuaNodeStr); if (isLua == null) { targetFileData.mIsLua = true; } else { targetFileData.mIsLua = isLua.InnerText == "true" ? true : false; } //所有变量 XmlNode alldataNode = doc.SelectSingleNode(baseCmdNodeStr); if (alldataNode != null) { XmlNodeList alldataNodeList = alldataNode.ChildNodes; for (int i = 0; i < alldataNode.ChildNodes.Count; i++) { if (alldataNodeList[i].Name == baseCmdNodeNameStr) { XmlElement element = (XmlElement)alldataNodeList[i];; ParamData targetCmd = new ParamData(); targetCmd.mType = element.GetAttribute("type"); targetCmd.mName = element.GetAttribute("name"); targetCmd.mValue = element.GetAttribute("value"); targetCmd.mComment = element.GetAttribute("comment"); targetCmd.mStringLen = element.GetAttribute("strLen"); targetCmd.mArrayLen = element.GetAttribute("arrayLen"); targetCmd.ParseParamType(); targetFileData.mAllBaseCmdList.Add(targetCmd); } } } //解析并生成脚本 sWriteFile(targetFileData); //存入根消息数据,以便生成总的handle CmdHandlerFileTool.CmdBigTypeData bigType = new CmdHandlerFileTool.CmdBigTypeData(); bigType.mCmdClassName = targetFileData.mClassName; bigType.mCmdTypeName = targetFileData.mGsCmd; bigType.mIsCS = targetFileData.mIsCS; bigType.mIsLua = targetFileData.mIsLua; CmdHandlerFileTool.AddBigType(targetFileData.mClassName, bigType); }
/// <summary> /// 接口实现 /// 解析Data XML /// </summary> public void ParserXml(string filePath, bool isOneFile = false) { XmlDocument doc = new XmlDocument(); doc.Load(filePath); DataStructFileData targetFileData = new DataStructFileData(); //文件名 XmlNode fileNameNode = doc.SelectSingleNode(NetCmdXmlParser.fileNameNodeStr); targetFileData.mClassName = fileNameNode.InnerText; //注释 XmlNode commentNode = doc.SelectSingleNode(paramDesNodeStr); targetFileData.mDescribe = commentNode.InnerText; //父级 XmlNode fatherNode = doc.SelectSingleNode(paramFatherNodeStr); targetFileData.mFather = fatherNode.InnerText; //是否导出C# XmlNode isCS = doc.SelectSingleNode(paramIsNeedCNodeStr); if (isCS == null) { targetFileData.mIsCS = true; } else { targetFileData.mIsCS = isCS.InnerText == "true" ? true : false; } //是否导出C# XmlNode isLua = doc.SelectSingleNode(paramIsNeedLuaNodeStr); if (isLua == null) { targetFileData.mIsLua = true; } else { targetFileData.mIsLua = isLua.InnerText == "true" ? true : false; } //所有变量 XmlNode paramNode = doc.SelectSingleNode(paramNodeStr); XmlNodeList paramNodeList = paramNode.ChildNodes; for (int i = 0; i < paramNode.ChildNodes.Count; i++) { if (paramNodeList[i].Name == paramNodeNameStr) { XmlElement element = (XmlElement)paramNodeList[i]; ParamData targetParam = new ParamData(); targetParam.mType = element.GetAttribute("type"); targetParam.mName = element.GetAttribute("name"); targetParam.mValue = element.GetAttribute("value"); targetParam.mComment = element.GetAttribute("comment"); targetParam.mStringLen = element.GetAttribute("strLen"); targetParam.mArrayLen = element.GetAttribute("arrayLen"); targetParam.mArrayDynLen = element.GetAttribute("arrayDymanicLen"); targetParam.ParseParamType(); //设置此条数据的类型 targetFileData.mParamList.Add(targetParam); } } //解析并生成脚本 sWriteFile(targetFileData); }
/// <summary> /// 接口实现 /// 解析消息XML /// </summary> public void ParserXml(string filePath, bool isOneFile = false) { XmlDocument doc = new XmlDocument(); doc.Load(filePath); CmdStructFileData targetFileData = new CmdStructFileData(); //文件名 XmlNode fileNameNode = doc.SelectSingleNode(NetCmdXmlParser.fileNameNodeStr); targetFileData.mClassName = fileNameNode.InnerText; //父类名 XmlNode fileFatherNameNode = doc.SelectSingleNode(cmdFatherDesNodeStr); targetFileData.mFatherClassName = fileFatherNameNode.InnerText; //文件名注释 XmlNode commentNode = doc.SelectSingleNode(cmdDesNodeStr); targetFileData.mDescribe = commentNode.InnerText; //协议消息名 XmlNode gscmd = doc.SelectSingleNode(cmdGsParamNodeStr); targetFileData.mGsParam = gscmd.InnerText; //自己消息ID XmlNode num = doc.SelectSingleNode(cmdNumNodeStr); targetFileData.mNum = num.InnerText; //父类消息ID XmlNode fathernum = doc.SelectSingleNode(cmdFatherNumNodeStr); if (fathernum == null) { Debug.LogError("父类消息值字段解析为空" + targetFileData.mClassName); } else { targetFileData.mFatherNum = fathernum.InnerText; } //路径文件夹名字 XmlNode pathname = doc.SelectSingleNode(cmdPathNameStr); if (pathname == null) { targetFileData.mPathName = ""; } else { targetFileData.mPathName = pathname.InnerText; } //是否需要解包 XmlNode isunpack = doc.SelectSingleNode(cmdIsUnPackNodeStr); targetFileData.mIsUnPack = isunpack.InnerText; //是否需要发包 XmlNode ispack = doc.SelectSingleNode(cmdIsPackNodeStr); targetFileData.mIsPack = ispack.InnerText; //是否需要Handler包 XmlNode ishandler = doc.SelectSingleNode(cmdIsHandlerNodeStr); if (ishandler == null) { targetFileData.mIsHandler = isunpack.InnerText; //不填默认看是否解包 } else { targetFileData.mIsHandler = ishandler.InnerText; } //是否需要lua XmlNode isneedlua = doc.SelectSingleNode(cmdIsNeedLuaNodeStr); targetFileData.mIsNeedLua = isneedlua.InnerText; //是否需要C XmlNode isneedc = doc.SelectSingleNode(cmdIsNeedCNodeStr); targetFileData.mIsNeedC = isneedc.InnerText; //常量 XmlNode cmdNode = doc.SelectSingleNode(cmdNodeStr); XmlNodeList cmdNodeList = cmdNode.ChildNodes; for (int i = 0; i < cmdNode.ChildNodes.Count; i++) { if (cmdNodeList[i].Name == cmdNodeNameStr) { XmlElement element = (XmlElement)cmdNodeList[i]; ParamData targetCmd = new ParamData(); targetCmd.mType = element.GetAttribute("type"); targetCmd.mName = element.GetAttribute("name"); targetCmd.mValue = element.GetAttribute("value"); targetCmd.mComment = element.GetAttribute("comment"); targetCmd.mStringLen = element.GetAttribute("strLen"); targetCmd.mArrayLen = element.GetAttribute("arrayLen"); targetCmd.mArrayDynLen = element.GetAttribute("arrayDymanicLen"); targetCmd.ParseParamType(); targetFileData.mCmdList.Add(targetCmd); } } bool isunpack_bool = false; bool ispack_bool = false; bool ishandler_bool = false; bool islua_bool = false; bool isc_bool = false; if (targetFileData.mIsUnPack == "true") { isunpack_bool = true; } if (targetFileData.mIsPack == "true") { ispack_bool = true; } if (targetFileData.mIsHandler == "true") { ishandler_bool = true; } if (targetFileData.mIsNeedC == "true") { isc_bool = true; } if (targetFileData.mIsNeedLua == "true") { islua_bool = true; } sWriteFile(isunpack_bool, ispack_bool, ishandler_bool, islua_bool, isc_bool, targetFileData); //存入数据,方便生成总的handle文件 if (ishandler_bool && !isOneFile) { if (isunpack_bool) { CmdHandlerFileTool.CmdSmallTypeData smallType = new CmdHandlerFileTool.CmdSmallTypeData(); smallType.mGsClassName = targetFileData.mClassName; smallType.mGsParamName = targetFileData.mGsParam; smallType.mIsCS = isc_bool; smallType.mIsLua = islua_bool; smallType.isNeedLua = islua_bool; CmdHandlerFileTool.CmdBigTypeData ownerBigType = CmdHandlerFileTool.GetBigType(targetFileData.mFatherClassName); ownerBigType.AddSubSmallType(smallType); } } }