public void Procedure_OnDealSingleExcel(ExcelData excelData) { PreDealExcelIndex++; IDealSingleExcel generateCode = new Generate_Server_Java_JsonCode(); IDealSingleExcel generateRes = new Generate_Server_Java_JsonFile(); List <List <string> > allRows = excelData.GetAllRows(); int rowCount = allRows.Count; for (int i = 0; i < rowCount; i++) { generateRes.DealRow(excelData, i); } generateCode.Execute(excelData, (ExcelData d1, bool r1) => { if (r1) { AddDelayRun(() => { generateRes.Execute(excelData, (ExcelData d2, bool r2) => { if (r2) { m_ExcelDataList.Add(excelData); DealExcelIndex++; if (PreDealExcelIndex == DealExcelIndex) //如果所有的Excel都处理完了,切到下一个流程(整体处理) { Console.WriteLine("PreDealExcelIndex:" + PreDealExcelIndex.ToString()); AddDelayRun(() => { Procedure_OnAllExcelDealFinish(m_ExcelDataList); }); } } }); }); } }); }
public bool Procedure_GenerateBuildFlatBufferCode(ExcelData excelData) { List <List <string> > allRows = excelData.GetAllRows(); int rowCount = allRows.Count; List <string> typeList = allRows[1]; string scriptline = ""; int arrayStart = 0; //当遇到数组的时候会变成1; 遇到最后一个数组元素的时候变成 2 List <TableArrayElementInfo> arrayList = new List <TableArrayElementInfo>(); //记录所有的数组单元格数据(必须是连贯的) for (int i = 3; i < rowCount; i++) { //offsets[{0}] = DR{1}.CreateDR{2}(fbb, {3}); List <string> cellList = allRows[i]; string strParam = ""; for (int j = 0; j < cellList.Count; j++) { string cellName = allRows[0][j]; //字段名称 string wordType = typeList[j].ToLower(); string cellStr = cellList[j]; string wordArrayName = null; if (cellName.Contains(":")) { wordArrayName = cellName.Split(':')[0]; if (arrayStart == 0) { arrayStart = 1; arrayList.Clear(); //arrayList.Add(new TableArrayElementInfo(cellName, wordType, cellStr, excelData.Name)); } } if (j + 1 < cellList.Count) //预判下一个值(如果不是最后一个) { string nextCellName = allRows[0][j + 1]; //字段名称 if (nextCellName.Contains(":")) { string nextWordArrayName = nextCellName.Split(':')[0]; if (!nextWordArrayName.Equals(wordArrayName)) //如果下一个单元格和当前单元格不是一个数组里的 { if (arrayStart == 1) { arrayStart = 2; } } } else { if (arrayStart == 1) { arrayStart = 2; } } } else { //如果已经是最后一个了 if (arrayStart == 1) { arrayStart = 2; } } string cellParam = ""; if (arrayStart == 0) //普通单元格 { cellParam = GetCellCodeString(wordType, cellStr); //添加单个元素 strParam = strParam + cellParam + ","; } else if (arrayStart == 1) //同一数组添加 { arrayList.Add(new TableArrayElementInfo(cellName, wordType, cellStr, excelData.Name)); } else if (arrayStart == 2) //整个数组解析成代码 { arrayList.Add(new TableArrayElementInfo(cellName, wordType, cellStr, excelData.Name)); cellParam = GetCellArrayCodeString(arrayList); strParam = strParam + cellParam + ","; arrayStart = 0; } } strParam = strParam.Substring(0, strParam.Length - 1); string addline = string.Format(Template.Template_GenerateBytesLine, i - 3, excelData.Name, excelData.Name, strParam); scriptline = scriptline + addline; } string generateByteFilePath = System.IO.Path.Combine(Setting.GenerateByteFilePath, string.Format("Table_{0}.bytes", excelData.Name)); generateByteFilePath = generateByteFilePath.Replace(@"\", @"/"); string script = string.Format(Template.Template_CSharp_GenearteBytes, excelData.Name, generateByteFilePath, excelData.Name, excelData.Name, rowCount - 3, scriptline, excelData.Name, excelData.Name, excelData.Name, excelData.Name, excelData.Name); //Console.WriteLine(script); string codePath = System.IO.Path.Combine(Setting.GenerateBuildFlatCodePath, "GenerateByte_" + excelData.Name + ".cs"); if (Tools.GenerateFile(script, codePath)) { Debug.Log("创建生成二进制代码" + codePath + "成功!"); } //添加到管理器的代码 GenerateManagerCode = GenerateManagerCode + string.Format(Template.Template_AddToGenerateManager, excelData.Name, excelData.Name); SetGenerateCodeFinish(excelData.FileName); //添加到FlatBufferTableManager(项目中使用) GenerateCode_FlatTableManager_Content(excelData); if (IsAllCodeGenerateFinish) { GenerateCode_FlatTableManager(excelData); OnCodeGenerateFinish(excelData); } return(true); }