using System.Collections.Generic; using System.IO; using UnityEditor; using UnityEngine; namespace PublicTools.XMLDataBase { /// /// 用来自动刷新和创建目标源数据库 /// 自动刷新并生成xml文件,默认生成的文本是不可写的,同时在rootDirPath根目录下生成 /// public class XDataCloneEditor : EditorWindow { private string rootDirPath = Application.streamingAssetsPath; private string localPath = "LocalData"; private string publicPath = "PublicData"; public string suffix = ".xml"; private bool isLogMsg = true; [MenuItem("Window/General/XDataWindow", validate = false, priority = 10)] private static void XDataClone() { XDataCloneEditor bw = GetWindow(typeof(XDataCloneEditor), false, "XML数据管理器", true) as XDataCloneEditor; bw.ShowPopup(); bw.autoRepaintOnSceneChange = true; } /// /// /// private void OnGUI() { rootDirPath = EditorGUILayout.TextField("资源根路径", rootDirPath); localPath = EditorGUILayout.TextField("不可写路径", localPath); publicPath = EditorGUILayout.TextField("可写路径", publicPath); isLogMsg = GUILayout.Toggle(isLogMsg, "输出日志"); suffix = EditorGUILayout.TextField("特定后缀", suffix); if (GUILayout.Button("刷新xml info", GUILayout.Width(100))) { //XSql.Instance.ConnctXsql(rootDirPath, true); } } /// /// 遍历某个文件夹下所有文件,并得到指定类型的文件 /// /// /// public List GetAllFile(string dir, List fileList, string suffix) { if (fileList == null) { fileList = new List(); } DirectoryInfo d = new DirectoryInfo(dir); FileSystemInfo[] fsinfos = d.GetFileSystemInfos(); foreach (FileSystemInfo fsinfo in fsinfos) { if (fsinfo is DirectoryInfo) //判断是否为文件夹 { GetAllFile(fsinfo.FullName, fileList, suffix); } else { string full = fsinfo.FullName; if (full.EndsWith(suffix)) { fileList.Add(fsinfo); } } } return fileList; } } }