123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using System.Collections.Generic;
- using System.IO;
- using UnityEditor;
- using UnityEngine;
- namespace PublicTools.XMLDataBase
- {
- /// <summary>
- /// 用来自动刷新和创建目标源数据库
- /// 自动刷新并生成xml文件,默认生成的文本是不可写的,同时在rootDirPath根目录下生成
- /// </summary>
- 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;
- }
- /// <summary>
- ///
- /// </summary>
- 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);
- }
- }
- /// <summary>
- /// 遍历某个文件夹下所有文件,并得到指定类型的文件
- /// </summary>
- /// <param name="dir"></param>
- /// <param name="fileList"></param>
- public List<FileSystemInfo> GetAllFile(string dir, List<FileSystemInfo> fileList, string suffix)
- {
- if (fileList == null)
- {
- fileList = new List<FileSystemInfo>();
- }
- 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;
- }
- }
- }
|