//public bool SaveGlobalQueryTable(string applicationPath, string name, Dictionary<int, ProtoTable.GlobalResQueryTable> data) //{ // if(null == data) // { // return false; // } // string purName = Path.GetFileNameWithoutExtension(name); // var excelPath = CombinePath(applicationPath, purName, FileExtensionType.FET_XLSX); // if(string.IsNullOrEmpty(excelPath)) // { // return false; // } // ExcelUnit unit = new ExcelUnit(excelPath, FileAccess.ReadWrite); // if (!unit.Init()) // { // unit.Close(); // return false; // } // if(!unit.LoadProtoBase()) // { // unit.Close(); // return false; // } // if(!unit.SaveGlobalQueryTable(data)) // { // unit.Close(); // return false; // } // unit.generateText(applicationPath); // bool succeed = unit.succeed; // if(succeed) // { // ExcelHelper.ConvertAsset(unit.SheetName + ".txt"); // } // unit.Close(); // if(!succeed) // { // return false; // } // return true; //} public bool Convert(string applicationPath, string name, ExcelHelper.ConvertType eConvertType) { string purName = Path.GetFileNameWithoutExtension(name); var excelPath = CombinePath(applicationPath, purName, FileExtensionType.FET_XLSX); if (!string.IsNullOrEmpty(excelPath)) { ExcelUnit unit = new ExcelUnit(excelPath); unit.Init(); unit.LoadProtoBase(); if (unit.succeed) { if (eConvertType == ExcelHelper.ConvertType.CT_PROTO) { var protoDir = Path.GetFullPath(applicationPath + ExcelConfig.PROTO_PATH); if (!Directory.Exists(protoDir)) { Directory.CreateDirectory(protoDir); } unit.CreateProto(protoDir); } else { unit.generateText(applicationPath); } } unit.Close(); return(unit.succeed); } return(false); }
protected void OnGUI() { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("过滤器", GUILayout.Width(100)); filter = EditorGUILayout.TextField(filter, GUILayout.Width(100)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("刷新", GUILayout.Width(100))) { _ListAllExcelFiles(); } if (GUILayout.Button("全选", GUILayout.Width(100))) { for (int i = 0; i < fileNames.Count; ++i) { fileNames [i].bSelected = true; } } if (GUILayout.Button("反选", GUILayout.Width(100))) { for (int i = 0; i < fileNames.Count; ++i) { fileNames [i].bSelected = !fileNames[i].bSelected; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("转表-PROTO", GUILayout.Width(100))) { for (int i = 0; i < fileNames.Count; ++i) { if (fileNames [i].bSelected) { if (ExcelManager.Instance().Convert(Application.dataPath, fileNames [i].name, ExcelHelper.ConvertType.CT_PROTO)) { UnityEngine.Debug.LogFormat("<color=#00ff00>convert <color=#ffff00>{0}.proto</color> succeed !!</color>", fileNames [i].name); } else { UnityEngine.Debug.LogFormat("<color=#ff0000>convert <color=#ffff00>{0}.proto</color> succeed !!</color>", fileNames [i].name); } } } } if (GUILayout.Button("转表-CS", GUILayout.Width(100))) { for (int i = 0; i < fileNames.Count; ++i) { if (fileNames [i].bSelected) { var dir = Path.GetFullPath(Application.dataPath + ExcelConfig.XLSX_PATH + fileNames [i].name + ".xls"); var excelUnit = new ExcelUnit(dir); excelUnit.Init(); if (excelUnit.succeed) { string proto_path = Path.GetFullPath(Application.dataPath + ExcelConfig.PROTO_PATH + excelUnit.SheetName + ".proto"); string out_path = Path.GetFullPath(Application.dataPath + ExcelConfig.TABLE_SCRIPTS_PATH + excelUnit.SheetName + ".cs"); string ccode_path = Path.GetFullPath(Application.dataPath + ExcelConfig.TABLE_SCRIPTS_CCODE_PATH + excelUnit.SheetName + ".cc"); ProtoBuf.CodeGenerator.CommandLineOptions.BuildXsxl2Cs(proto_path, out_path, ccode_path); } else { UnityEngine.Debug.LogErrorFormat("表{0}转cs文件失败!", fileNames [i]); } excelUnit.Close(); } } } if (GUILayout.Button("转表-TXT", GUILayout.Width(100))) { for (int i = 0; i < fileNames.Count; ++i) { if (fileNames [i].bSelected) { var dir = Path.GetFullPath(Application.dataPath + ExcelConfig.XLSX_PATH + fileNames [i].name + ".xls"); var excelUnit = new ExcelUnit(dir); excelUnit.Init(); excelUnit.LoadProtoBase(); excelUnit.generateText(Application.dataPath); if (excelUnit.succeed) { UnityEngine.Debug.LogFormat("<color=#00ff00>convert <color=#ffff00>{0}.txt</color> succeed !!</color>", excelUnit.SheetName); ExcelHelper.ConvertAsset(excelUnit.SheetName + ".txt"); } else { UnityEngine.Debug.LogFormat("<color=#ff0000>convert <color=#ffff00>{0}.txt</color> succeed !!</color>", excelUnit.SheetName); } var txtPath = Path.GetFullPath(Application.dataPath + ExcelConfig.TXT_SAVE_PATH + excelUnit.SheetName + ".txt"); if (File.Exists(txtPath)) { File.Delete(txtPath); } excelUnit.Close(); } } } EditorGUILayout.EndHorizontal(); //excel-table-name _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos); EditorGUILayout.BeginVertical(); var defColor = GUI.color; for (int i = 0; i < fileNames.Count; ++i) { if (fileNames [i].name.StartsWith(filter)) { EditorGUILayout.BeginHorizontal(); if (i % 2 == 0) { GUI.color = Color.yellow; } else { GUI.color = Color.cyan; } EditorGUILayout.LabelField(fileNames [i].name); fileNames [i].bSelected = EditorGUILayout.Toggle(fileNames [i].bSelected); EditorGUILayout.EndHorizontal(); } } GUI.color = defColor; EditorGUILayout.EndVertical(); EditorGUILayout.EndScrollView(); }