private void CreateClass(ExcelInfo excelInfo)
        {
            string csPath = EditorUtils.DataPath + ClassPath;

            if (!Directory.Exists(csPath))
            {
                Directory.CreateDirectory(csPath);
            }
            EditorExcelTools.CreateClass(excelInfo.excelFullPath, excelInfo.classInfoName, excelInfo.classTableName,
                                         string.Format(csPath + "{0}.cs", excelInfo.classTableName));
        }
        private static void ExportExcel()
        {
            if (!Directory.Exists(ExcelPath))
            {
                Directory.CreateDirectory(ExcelPath);
            }

            var files = Directory.GetFiles(ExcelPath, "*.*", SearchOption.TopDirectoryOnly)
                        .Where(p => p.EndsWith(".xlsx") || p.EndsWith(".xls"))
                        .Select(p => new
            {
                path = p,
                name = Path.GetFileNameWithoutExtension(p),
                list = Path.GetFileNameWithoutExtension(p).Split('#')
            })
                        .Where(p => !p.name.StartsWith("."))
                        .ToLookup(p => p.list.First())
                        .ToDictionary(p => p.Key, p => p.ToList().Select(q => q.path).ToArray());


            Debug.Log(files.Join("\n"));
            Debug.Log(JsonHelper.ToJson(files));

            string csPath = EditorUtils.DataPath + ClassPath;

            if (!Directory.Exists(csPath))
            {
                Directory.CreateDirectory(csPath);
            }
            foreach (KeyValuePair <string, string[]> pair in files)
            {
                foreach (string excelFullPath in pair.Value)
                {
                    string classInfoName  = pair.Key.Replace("Table", "Info");
                    string classTableName = pair.Key;
                    EditorExcelTools.CreateClass(excelFullPath, classInfoName, classTableName,
                                                 string.Format(csPath + "{0}.cs", classTableName));

                    string path     = EditorUtils.DataPath + excelFullPath;
                    string savePath = EditorUtils.DataPath + TablePath;
                    Debug.Log(path + "\n" + savePath);
                    EditorExcelTools.ExportTo(_tableType, excelFullPath, new[] { savePath });
                }
            }

            AssetDatabase.Refresh();
        }
Example #3
0
        public void DrawGUI(int limit = 0)
        {
            GUILayout.BeginVertical(GUILayout.MaxWidth(limit));
            GUILayout.Space(offset);
            selectTarget = EditorGUILayout.ObjectField("Excel来源文件:", selectTarget, typeof(Object), false);

            if (oldTarget != selectTarget)
            {
                oldTarget = selectTarget;
                check     = null;
                if (excelInfo != null && selectTarget != null)
                {
                    rename = excelInfo.SetData(AssetDatabase.GetAssetPath(selectTarget));
                }
            }

            if (excelInfo != null && selectTarget != null)
            {
                outPut = EditorGUILayout.ObjectField("Excel输出文件:", outPut, typeof(Object), false);
                EditorGUILayout.TextField("名称:", excelInfo.excelName);
                EditorGUILayout.TextField("来源路径:", excelInfo.excelFullPath);
                EditorGUILayout.TextField("输出路径:", excelInfo.tableName);
                EditorGUILayout.TextField("Sheet:", excelInfo.sheet.ToString());
                EditorGUILayout.TextField("Table:", excelInfo.classTableName);
                EditorGUILayout.TextField("Info:", excelInfo.classInfoName);

                GUILayout.Space(offset);
                if (rename == true)
                {
                    if (EditorUtility.DisplayDialog("提示", "名称不符合规范!是否继续重命名?", "确定", "取消"))
                    {
                        string   sourcePath = AssetDatabase.GetAssetPath(selectTarget);
                        FileInfo fileInfo   = new FileInfo(sourcePath);
                        string   temp       = fileInfo.Name.Replace(fileInfo.Extension, "");
                        string   newPath    = sourcePath.Replace(temp, temp + "Table");
                        File.Move(EditorUtils.DataPath + sourcePath, EditorUtils.DataPath + newPath);
                        AssetDatabase.Refresh();
                        Debug.LogError("名字不符和规范!已经重命名!");
                        selectTarget = AssetDatabase.LoadAssetAtPath(newPath, typeof(Object));
                        rename       = excelInfo.SetData(newPath);
                    }
                    else
                    {
                        this.CloseWindow();
                    }
                }
                else if (rename == false)
                {
                    if (GUILayout.Button("Check"))
                    {
                        check = EditorUtils.GetClassByName(excelInfo.classTableName);
                        check = EditorUtils.GetClassByName(excelInfo.classInfoName);
                    }
                }
            }

            GUILayout.Space(offset);

            GUILayout.BeginHorizontal();
            if (check == true)
            {
                if (GUILayout.Button("Yes"))
                {
                    if (callback != null)
                    {
                        callback(excelInfo);
                    }
                    CloseWindow();
                }
                if (GUILayout.Button("Not"))
                {
                    CloseWindow();
                }
            }
            else if (check == false)
            {
                if (GUILayout.Button("CreateClass"))
                {
                    if (excelInfo != null)
                    {
                        string csPath = EditorUtils.DataPath + ExcelWindow.ClassPath;
                        if (!Directory.Exists(csPath))
                        {
                            Directory.CreateDirectory(csPath);
                        }
                        EditorExcelTools.CreateClass(excelInfo.excelFullPath, excelInfo.classInfoName, excelInfo.classTableName, string.Format(csPath + "{0}.cs", excelInfo.classTableName));
                    }
                    AssetDatabase.Refresh();
                    check = true;
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(offset);
            if (GUILayout.Button("Close"))
            {
                CloseWindow();
            }

            GUILayout.EndVertical();
        }