XDataCloneEditor.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace PublicTools.XMLDataBase
  6. {
  7. /// <summary>
  8. /// 用来自动刷新和创建目标源数据库
  9. /// 自动刷新并生成xml文件,默认生成的文本是不可写的,同时在rootDirPath根目录下生成
  10. /// </summary>
  11. public class XDataCloneEditor : EditorWindow
  12. {
  13. private string rootDirPath = Application.streamingAssetsPath;
  14. private string localPath = "LocalData";
  15. private string publicPath = "PublicData";
  16. public string suffix = ".xml";
  17. private bool isLogMsg = true;
  18. [MenuItem("Window/General/XDataWindow", validate = false, priority = 10)]
  19. private static void XDataClone()
  20. {
  21. XDataCloneEditor bw = GetWindow(typeof(XDataCloneEditor), false, "XML数据管理器", true) as XDataCloneEditor;
  22. bw.ShowPopup();
  23. bw.autoRepaintOnSceneChange = true;
  24. }
  25. /// <summary>
  26. ///
  27. /// </summary>
  28. private void OnGUI()
  29. {
  30. rootDirPath = EditorGUILayout.TextField("资源根路径", rootDirPath);
  31. localPath = EditorGUILayout.TextField("不可写路径", localPath);
  32. publicPath = EditorGUILayout.TextField("可写路径", publicPath);
  33. isLogMsg = GUILayout.Toggle(isLogMsg, "输出日志");
  34. suffix = EditorGUILayout.TextField("特定后缀", suffix);
  35. if (GUILayout.Button("刷新xml info", GUILayout.Width(100)))
  36. {
  37. //XSql.Instance.ConnctXsql(rootDirPath, true);
  38. }
  39. }
  40. /// <summary>
  41. /// 遍历某个文件夹下所有文件,并得到指定类型的文件
  42. /// </summary>
  43. /// <param name="dir"></param>
  44. /// <param name="fileList"></param>
  45. public List<FileSystemInfo> GetAllFile(string dir, List<FileSystemInfo> fileList, string suffix)
  46. {
  47. if (fileList == null)
  48. {
  49. fileList = new List<FileSystemInfo>();
  50. }
  51. DirectoryInfo d = new DirectoryInfo(dir);
  52. FileSystemInfo[] fsinfos = d.GetFileSystemInfos();
  53. foreach (FileSystemInfo fsinfo in fsinfos)
  54. {
  55. if (fsinfo is DirectoryInfo) //判断是否为文件夹
  56. {
  57. GetAllFile(fsinfo.FullName, fileList, suffix);
  58. }
  59. else
  60. {
  61. string full = fsinfo.FullName;
  62. if (full.EndsWith(suffix))
  63. {
  64. fileList.Add(fsinfo);
  65. }
  66. }
  67. }
  68. return fileList;
  69. }
  70. }
  71. }