private void UpdateScriptObj(string path) { PropertyDic.Clear(); PropertyNames = null; if (!string.IsNullOrEmpty(path)) { OutputName = Path.GetFileNameWithoutExtension(path); /** * string name = Path.GetFileNameWithoutExtension(path); * if (string.IsNullOrEmpty(name)) return; * name = string.Format("{0}{1}", PathEditorTool.BuildCSharpNamespace, name); * string dllPath = InfoTool.PathConfig[EditorPrefsKey.CSharpDllPath]; * if (string.IsNullOrEmpty(dllPath)) return; * dllPath = string.Format("{0}/{1}", dllPath, PathEditorTool.BuildCSharpDll); * Assembly assembly = Assembly.LoadFile(dllPath); // 加载程序集(EXE 或 DLL) * object obj = assembly.CreateInstance(name); **/ object obj = InfoTool.InstantiationScript(path); if (obj != null) { Type t = obj.GetType(); List <string> names = new List <string>(); names.Add("None"); foreach (PropertyInfo pi in t.GetProperties()) { names.Add(pi.Name); PropertyDic.Add(pi.Name, pi.PropertyType); } if (names.Count > 0) { PropertyNames = names.ToArray(); } } } }
private IEnumerator Read(string path, Action <string, Color> setTipVal, Action finish) { if (mWorkbook == null) { mWorkbook = ExcelMgr.ReadExcel(mPath); } yield return(new WaitForEndOfFrame()); if (mWorkbook == null) { setTipVal(string.Format("Excel路径<{0}>没有找到指定配置表!", mPath), Color.red); } else { mProgressBar.value = 0.01f; setTipVal("读取完成", Color.green); yield return(new WaitForEndOfFrame()); List <object> outputList = new List <object>(); string cfgName = null; string[] keys = null; int count = mWorkbook.NumberOfSheets; var pgs = 0.9f / count; for (var page = 0; page < count; page++) { ISheet sheet = mWorkbook.GetSheetAt(page); if (sheet != null) { if (keys == null) { IRow row = ExcelMgr.GetSheetRow(sheet, 1); keys = new string[row.LastCellNum]; if (row != null && row.LastCellNum > 1) { for (int c = 0; c < row.LastCellNum; c++) { var str = row.GetCell(c).ToString(); if (string.IsNullOrEmpty(str)) { yield return(new WaitForEndOfFrame()); goto ROW_CELL_IS_NULL; } keys[c] = str; } } else { yield return(new WaitForEndOfFrame()); goto DECODE_EXCEL_FAIL; } } var rowLen = sheet.LastRowNum + 1; mProgressBar.value = (pgs * page) - (rowLen * pgs) * 2; if (rowLen <= 2) { continue; } for (var r = 2; r < rowLen; r++) { IRow row = ExcelMgr.GetSheetRow(sheet, r); if (row != null && row.LastCellNum > 1) { object cfg = null; for (int c = 0; c < row.LastCellNum; c++) { var key = keys[c]; if (c == 0) { if (!string.IsNullOrEmpty(key)) { cfg = InfoTool.InstantiationScript(key); if (cfg == null) { goto GET_ASSEMBLY_FAIL; } cfgName = key; yield return(new WaitForEndOfFrame()); } else { yield return(new WaitForEndOfFrame()); goto GET_ASSEMBLY_FAIL; } } else { var cell = row.GetCell(c); if (cell == null) { continue; } WriteCfg(keys[c], row.GetCell(c).ToString(), ref cfg); } } if (cfg == null) { continue; } outputList.Add(cfg); } mProgressBar.value = (pgs * page) - (rowLen * pgs) * r; yield return(new WaitForEndOfFrame()); } } } mProgressBar.value = 0.9f; setTipVal("解码完成", Color.green); yield return(new WaitForEndOfFrame()); string outputPath = string.Format("{0}{1}", PathTool.DataPath, PathTool.Temp); Config.OutputConfig <object>(outputPath, cfgName, outputList, SuffixTool.TableInfo.ToLower()); mProgressBar.value = 1.0f; } goto FINISH; ROW_CELL_IS_NULL : MessageBox.Error("配置表字段key为null"); goto RETURN; GET_ASSEMBLY_FAIL : MessageBox.Error("程序集没有识别到Assembly对应的脚本。"); goto RETURN; DECODE_EXCEL_FAIL : MessageBox.Error("解析excel失败"); goto RETURN; RETURN : Clear(); FINISH: setTipVal("导出完成", Color.green); Clear(); finish(); }