void addItem(ImportConfig config)
        {
            EditorGUILayout.BeginHorizontal();

            GUILayout.Label(config.Name, EditorStyles.boldLabel);
            GUILayout.FlexibleSpace();

            var destPath   = System.IO.Path.Combine(KSwordKitConst.KSwordKitContentsDirectory, config.Name);
            var isExists   = System.IO.Directory.Exists(destPath);
            var buttonName = "导入";

            if (isExists)
            {
                buttonName = "重新导入";
            }

            if (GUILayout.Button(buttonName, GUILayout.Width(110)))
            {
                var error = config.Import(new System.IO.DirectoryInfo(System.IO.Path.Combine(KSwordKitConst.KSwordKitContentsSourceDiretory, config.Name)).FullName, destPath);
                EditorUtility.DisplayDialog("导入部件 '" + config.Name + "' ", string.IsNullOrEmpty(error) ?"导入成功!": "导入失败: \n" + error, "确定");
                AssetDatabase.Refresh();
            }

            EditorGUI.BeginDisabledGroup(!isExists);
            if (GUILayout.Button("删除", GUILayout.Width(110)))
            {
                var error = config.Delete();
                EditorUtility.DisplayDialog("删除部件 '" + config.Name + "' ", string.IsNullOrEmpty(error) ? "删除成功!" : "删除失败: \n" + error, "确定");
                AssetDatabase.Refresh();
            }
            EditorGUI.EndDisabledGroup();

            EditorGUILayout.EndHorizontal();
        }
        void addItem(ImportConfig config, string name, string path)
        {
            EditorGUILayout.BeginHorizontal();

            GUILayout.Label(name, EditorStyles.boldLabel);
            GUILayout.FlexibleSpace();

            var isExists = System.IO.Directory.Exists(System.IO.Path.Combine(KSwordKitConst.KSwordKitContentsDirectory, name));

            if (isExists)
            {
                if (GUILayout.Button("重新导入", GUILayout.Width(110)))
                {
                    import(config, name, path);
                }
            }
            else
            {
                if (GUILayout.Button("导入", GUILayout.Width(110)))
                {
                    import(config, name, path);
                }
            }

            EditorGUI.BeginDisabledGroup(!isExists);
            if (GUILayout.Button("删除", GUILayout.Width(110)))
            {
                delete(config, name, path);
            }
            EditorGUI.EndDisabledGroup();

            EditorGUILayout.EndHorizontal();
        }
        void delete(ImportConfig config, string name, string path)
        {
            //Debug.Log(KSwordKitConst.KSwordKitName + ": 正准备删除部件 " + name + " ...");

            //var cPath = System.IO.Path.Combine(KSwordKitConst.KSwordKitContentsDirectory, name);
            //var spath = System.IO.Path.Combine(KSwordKitConst.KSwordKitContentsSourceDiretory, name);
            //var epath = System.IO.Path.Combine(KSwordKitConst.KSwordKitExamplesDirtory, "Example" + name);

            //if (System.IO.Directory.Exists(cPath))
            //    FileUtil.DeleteFileOrDirectory(cPath);

            //foreach (var item in config.FileSettingList)
            //{
            //    if (!string.IsNullOrEmpty(item.ExamplePath))
            //        if (System.IO.Directory.Exists(epath))
            //            FileUtil.DeleteFileOrDirectory(epath);

            //    if (item.IsDir)
            //    {
            //        if (System.IO.Directory.Exists(item.ImportPath))
            //            FileUtil.DeleteFileOrDirectory(item.ImportPath);
            //    }
            //    else
            //    {
            //        if (System.IO.File.Exists(item.ImportPath))
            //            FileUtil.DeleteFileOrDirectory(item.ImportPath);
            //    }
            //}
            //AssetDatabase.Refresh();
            //Debug.Log(KSwordKitConst.KSwordKitName + ": 已删除部件 " + name);
        }
        void import(ImportConfig config, string name, string path)
        {
            //Debug.Log(KSwordKitConst.KSwordKitName + ": 正准备导入部件 " + name + " ...");
            //if(!System.IO.Directory.Exists(path))
            //{
            //    Debug.Log(KSwordKitConst.KSwordKitName + ": 导入部件 " + name + " 失败!源代码不存在。");
            //    return;
            //}
            //var cPath = System.IO.Path.Combine(KSwordKitConst.KSwordKitContentsDirectory, name);
            //var spath = System.IO.Path.Combine(KSwordKitConst.KSwordKitContentsSourceDiretory, name);

            //var error = CopyFolder(config, true, name, path, cPath);
            //foreach (var item in config.FileSettingList)
            //{
            //    if (!string.IsNullOrEmpty(item.ExamplePath))
            //        error += CopyFolder(config, false, name,
            //            new System.IO.DirectoryInfo(System.IO.Path.Combine(spath, item.ExamplePath)).FullName,
            //            System.IO.Path.Combine(KSwordKitConst.KSwordKitExamplesDirtory, "Example" + name));

            //    if (string.IsNullOrEmpty(item.Path) || string.IsNullOrEmpty(item.ImportPath))
            //        continue;

            //    if (item.IsDir)
            //    {
            //        error += CopyFolder(config, false, name, new System.IO.DirectoryInfo(System.IO.Path.Combine(spath, item.Path)).FullName, new System.IO.DirectoryInfo(item.ImportPath).FullName);
            //    }
            //    else
            //    {
            //        try
            //        {
            //            var fName = System.IO.Path.GetFileName(item.ImportPath);
            //            var dirpath = item.ImportPath.Substring(0, item.ImportPath.Length - fName.Length - 1);
            //            if (!System.IO.Directory.Exists(dirpath))
            //            {
            //                System.IO.Directory.CreateDirectory(dirpath);
            //            }
            //            EditorUtility.DisplayProgressBar(KSwordKitConst.KSwordKitName + ": 拷贝部件 " + name, "正在拷贝:" + fName, UnityEngine.Random.Range(0f, 1));
            //            System.IO.File.Copy(new System.IO.DirectoryInfo(System.IO.Path.Combine(spath, item.Path)).FullName, System.IO.Path.Combine(dirpath, fName), true);
            //        }catch(System.Exception e)
            //        {
            //            error += e.Message;
            //        }

            //        EditorUtility.ClearProgressBar();
            //    }
            //}
            //AssetDatabase.Refresh();
            //if (string.IsNullOrEmpty(error))
            //    Debug.Log(KSwordKitConst.KSwordKitName + ": 导入部件 " + name + " 成功!");
        }
        private void OnGUI()
        {
            EditorGUILayout.Space(10);
            GUILayout.Label("新部件配置文件: " + newComponentPath);
            reSelect = string.IsNullOrEmpty(newComponentPath) ? "已存在新部件配置文件" : "重新已存在的新部件配置文件";
            EditorGUILayout.BeginHorizontal();
            if (isCreateNew)
            {
                if (GUILayout.Button("删除生成的配置文件"))
                {
                    System.IO.File.Delete(newComponentPath);
                    System.IO.File.Delete(newComponentPath + ".meta");
                    newComponentPath = string.Empty;
                    reSelect         = string.Empty;
                    isCreateNew      = false;
                    AssetDatabase.Refresh();
                }
            }
            else
            {
                if (GUILayout.Button(reSelect))
                {
                    newComponentPath = EditorUtility.OpenFilePanel("选择已存在的新部件配置文件", "Assets", "json");
                }
                if (reSelect == "重新已存在的新部件配置文件")
                {
                    if (GUILayout.Button("重置"))
                    {
                        newComponentPath = string.Empty;
                        reSelect         = string.Empty;
                    }
                }
                else
                {
                    if (GUILayout.Button("创建新部件的配置文件"))
                    {
                        newComponentPath = EditorUtility.SaveFilePanel("保存配置文件", "Assets", "ImportConfig", "json");
                        if (!string.IsNullOrEmpty(newComponentPath))
                        {
                            isCreateNew = true;
                            System.IO.File.WriteAllText(newComponentPath, defaultImportConfigContent);
                            AssetDatabase.Refresh();
                        }
                    }
                }
            }

            EditorGUILayout.EndHorizontal();

            if (!string.IsNullOrEmpty(newComponentPath))
            {
                newComonentContent = System.IO.File.ReadAllText(newComponentPath);
                newComonentContent = EditorGUILayout.TextArea(newComonentContent, GUILayout.Height(200));
                System.IO.File.WriteAllText(newComponentPath, newComonentContent);
                ImportConfig config = null;
                try
                {
                    config = JsonUtility.FromJson <ImportConfig>(newComonentContent);
                }catch (System.Exception e)
                {
                    Debug.LogError(KSwordKitConst.KSwordKitName + ": json格式不正确!" + e.Message);
                    errorloged = true;
                    return;
                }
                if (errorloged)
                {
                    errorloged = false;

                    var assembly = System.Reflection.Assembly.GetAssembly(typeof(ActiveEditorTracker));
                    var type     = assembly.GetType("UnityEditorInternal.LogEntries");
                    if (type == null)
                    {
                        type = assembly.GetType("UnityEditor.LogEntries");
                    }
                    var method = type.GetMethod("Clear");
                    method.Invoke(new object(), null);
                }
                EditorGUILayout.Space(10);
                EditorGUILayout.BeginVertical();
                EditorGUILayout.LabelField("部件名称:", config.Name);
                EditorGUILayout.LabelField("部件目录:", new System.IO.FileInfo(newComponentPath).Directory.FullName);
                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical();
                EditorGUILayout.LabelField("依赖:");
                var dependencies = string.Empty;
                foreach (var d in config.Dependencies)
                {
                    if (string.IsNullOrEmpty(dependencies))
                    {
                        dependencies = d;
                    }
                    else
                    {
                        dependencies += "\n" + d;
                    }
                }
                if (string.IsNullOrEmpty(dependencies))
                {
                    dependencies = "\t无";
                }
                EditorGUILayout.LabelField(dependencies);
                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical();
                EditorGUILayout.LabelField("示例代码位置:");
                var exampleFolderPaths = string.Empty;
                foreach (var e in config.ExampleFolderPaths)
                {
                    if (string.IsNullOrEmpty(exampleFolderPaths))
                    {
                        exampleFolderPaths = e;
                    }
                    else
                    {
                        exampleFolderPaths += "\n" + e;
                    }
                }
                if (string.IsNullOrEmpty(exampleFolderPaths))
                {
                    exampleFolderPaths = "\t无";
                }
                EditorGUILayout.LabelField(exampleFolderPaths);
                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical();
                EditorGUILayout.LabelField("特殊文件设置: ");
                var filesettings = string.Empty;
                foreach (var s in config.FileSettings)
                {
                    var str = (s.IsDir ? "文件夹:" : "文件:") + s.Path + " -> " + s.ImportPath;
                    if (string.IsNullOrEmpty(filesettings))
                    {
                        filesettings = str;
                    }
                    else
                    {
                        filesettings += "\n" + str;
                    }
                }
                if (string.IsNullOrEmpty(filesettings))
                {
                    filesettings = "\t无";
                }
                EditorGUILayout.LabelField(filesettings);
                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical();
                if (GUILayout.Button("导出新部件"))
                {
                    string error;
                    ExportNewComponent(newComponentPath, out error);
                    EditorUtility.DisplayDialog("导出新部件 '" + config.Name + "' ", string.IsNullOrEmpty(error) ? "成功!":"失败:" + error, "确定");
                }
                EditorGUILayout.EndVertical();
                EditorGUILayout.Space(10);
            }
        }
        string CopyFolder(ImportConfig config, bool useConfig, string name, string sourceDir, string destDir)
        {
            string error = "";

            //try
            //{
            //    if (!System.IO.Directory.Exists(destDir))
            //    {
            //        System.IO.Directory.CreateDirectory(destDir);
            //    }

            //    var cinfo = new System.IO.DirectoryInfo(System.IO.Path.Combine(System.IO.Path.Combine(KSwordKitConst.KSwordKitContentsSourceDiretory, name)));
            //    var icfnInfo = new System.IO.FileInfo(System.IO.Path.Combine(cinfo.FullName, ContentsEditor.ImportConfigFileName));

            //    string[] fileList = System.IO.Directory.GetFiles(sourceDir, "*");
            //    foreach (string f in fileList)
            //    {
            //        string fName = f.Substring(sourceDir.Length + 1);
            //        if (useConfig)
            //        {
            //            var fileinfo = new System.IO.FileInfo(f);

            //            if (fileinfo.FullName == icfnInfo.FullName)
            //                continue;
            //            var find = config.FileSettingList.Find((fs) => {
            //                if (fs.IsDir || string.IsNullOrEmpty(fs.Path) || string.IsNullOrEmpty(fs.ImportPath)) return false;
            //                if (new System.IO.DirectoryInfo(System.IO.Path.Combine(cinfo.FullName, fs.Path)).FullName == fileinfo.FullName) return true;
            //                return new System.IO.FileInfo(fs.Path).FullName == fileinfo.FullName;
            //            });

            //            if (find != null)
            //                continue;
            //        }

            //        EditorUtility.DisplayProgressBar(KSwordKitConst.KSwordKitName + ": 拷贝部件 "+ name, "正在拷贝:" + fName, UnityEngine.Random.Range(0f, 1));
            //        System.IO.File.Copy(System.IO.Path.Combine(sourceDir, fName), System.IO.Path.Combine(destDir, fName), true);
            //    }
            //    foreach (var dir in System.IO.Directory.GetDirectories(sourceDir, "*"))
            //    {
            //        if (useConfig)
            //        {
            //            var dirinfo = new System.IO.DirectoryInfo(dir);
            //            var f = config.FileSettingList.Find((fs) => {
            //                if (new System.IO.DirectoryInfo(System.IO.Path.Combine(cinfo.FullName, fs.ExamplePath)).FullName == dirinfo.FullName) return true;
            //                if (!fs.IsDir || string.IsNullOrEmpty(fs.Path) || string.IsNullOrEmpty(fs.ImportPath)) return false;
            //                return new System.IO.DirectoryInfo(System.IO.Path.Combine(cinfo.FullName, fs.Path)).FullName == dirinfo.FullName;
            //            });
            //            if (f != null)
            //                continue;
            //        }
            //        error += CopyFolder(config, useConfig, name, dir, System.IO.Path.Combine(destDir, dir.Substring(sourceDir.Length + 1)));
            //    }
            //}
            //catch (System.Exception e)
            //{
            //    error += e.Message;
            //}

            //EditorUtility.ClearProgressBar();

            return(error);
        }