private Dictionary <string, Item> _dictByMd5; //字典 public AssetUpdateAssetList Scan(string assetFolder) { if (string.IsNullOrEmpty(assetFolder)) { return(this); } var assetFolderLow = assetFolder.ToLower(); var fileList = new List <Item>(); XFolderTools.TraverseFiles(assetFolder, (fullPath) => { var assetPath = XPathTools.GetRelativePath(fullPath); var relaPath = XPathTools.SubRelativePath(assetFolder, assetPath); var updateItem = new Item(); updateItem.filePath = relaPath.ToLower(); updateItem.fileMd5 = XFileTools.GetMD5(assetPath); updateItem.fileSize = XFileTools.GetLength(assetPath); fileList.Add(updateItem); }, true); path = assetFolder; fileItems = fileList.ToArray(); return(this); }
public static void GenPrefabAndmaterial(string assetPath, List <string> exportPathList = null) { if (exportPathList == null) { exportPathList = new List <string>(); string selectRootPath = Path.GetDirectoryName(assetPath); string selectFileName = Path.GetFileNameWithoutExtension(assetPath); XFolderTools.TraverseFiles(selectRootPath, (fullPath) => { string fileEx = Path.GetExtension(fullPath).ToLower(); if (fileEx.Contains("controller")) { string fleRelaPath = XPathTools.GetRelativePath(fullPath); string fileRootPath = Path.GetDirectoryName(fleRelaPath); exportPathList.Add(fileRootPath); } }, true); } foreach (var exportRootPath in exportPathList) { string ctrlFilePath = XPathTools.Combine(exportRootPath, SpriteEditorTools.controllerName); string folderId = XStringTools.SplitPathKey(exportRootPath); string spriteSavePath = XPathTools.Combine(exportRootPath, string.Format("{0}.prefab", folderId)); string materialSavePath = XPathTools.Combine(exportRootPath, string.Format("{0}.mat", folderId)); var sprite = SpriteEditorTools.GeneratePrefabFromAnimationControllerFile(ctrlFilePath, spriteSavePath); var material = SpriteEditorTools.GenerateMaterialFromAnimationControllerFile(ctrlFilePath, materialSavePath); SpriteEditorTools.SetupMaterial(sprite, material); SpriteEditorTools.SetupBoxCollider(sprite); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } }
/// <summary> /// 从选择项中获取路径 /// </summary> /// <param name="suffixs"></param> /// <param name="isTrans"></param> /// <returns></returns> public static string[] GetPathsBySelections(string[] suffixs = null, bool isTraverse = false) { var selectedObjs = Selection.objects; List <string> retPathList = new List <string>(); if (selectedObjs != null && selectedObjs.Length > 0) { List <string> filePathList = new List <string>(); foreach (var selected in selectedObjs) { string selectPath = AssetDatabase.GetAssetPath(selected); if (File.Exists(selectPath)) //如果是文件 { filePathList.Add(selectPath); } else if (Directory.Exists(selectPath)) //如果是文件夹 { XFolderTools.TraverseFiles(selectPath, (fullPath) => { string realPath = XPathTools.GetRelativePath(fullPath); filePathList.Add(realPath); }, isTraverse); } } //筛选 HashSet <string> suffixSet = null; if (suffixs != null && suffixs.Length > 0) { suffixSet = new HashSet <string>(); foreach (var suffix in suffixs) { string lowSuffix = suffix.ToLower(); if (!suffixSet.Contains(lowSuffix)) { suffixSet.Add(lowSuffix); } } } foreach (var path in filePathList) { if (suffixSet != null) { string fileExtName = Path.GetExtension(path).ToLower(); if (suffixSet.Contains(fileExtName)) { retPathList.Add(path); } } else { retPathList.Add(path); } } } return(retPathList.ToArray()); }
private void ImportExAsset(string folderPath) { _assetFolderPath = folderPath; _assetFolderList = new List <string>(); XFolderTools.TraverseFiles(_assetFolderPath, (fullPath) => { string exName = Path.GetExtension(fullPath); _assetFolderList.Add(fullPath); }, true); RefreshAssetList(); }
//获取目录下第一个文件的后缀 private string GetFolderFirstFileExtension(string folderPath) { string ex = ""; XFolderTools.TraverseFiles(folderPath, (fullPath) => { if (!string.IsNullOrEmpty(ex)) { return; } ex = Path.GetExtension(fullPath); if (ex.Contains("DS_Store")) { ex = ""; } }); return(ex); }
public static void MenuGenSheetJson() { var selected = Selection.activeObject; string selectPath = AssetDatabase.GetAssetPath(selected); if (selectPath != "") { List <string> assetsList = new List <string>(); if (Directory.Exists(selectPath)) //是文件夹 { //对所有操作 XFolderTools.TraverseFiles(selectPath, (fullPath) => { string fileNameNExt = Path.GetFileNameWithoutExtension(fullPath).ToLower(); string fileExt = Path.GetExtension(fullPath).ToLower(); if (!AssetRuntimeUtil.IsImageFile(fullPath)) { return; } string assetPath = XPathTools.GetRelativePath(fullPath); assetsList.Add(assetPath); }); } else { assetsList.Add(selectPath); } foreach (var assetPath in assetsList) { GenSheetJson(assetPath); } } else { Debug.LogError("没有选中文件或文件夹"); } }
public void Sync(int version) { var syncItems = AssetSyncConfiger.GetInstance().syncItems; if (syncItems == null || syncItems.Count <= 0) { return; } string fullPath = XPathTools.Combine(AssetSyncConfiger.GetInstance().repositoryRootPath, string.Format("{0}", version)); string repositoryPath = fullPath; string versionFolderName = Path.GetFileNameWithoutExtension(fullPath); int curVersion = AssetSyncConfiger.GetInstance().GetRepositoryVersion(versionFolderName); if (curVersion > 0 && curVersion >= AssetSyncConfiger.GetInstance().minVersion) { foreach (var syncItem in syncItems) { string srcPath = syncItem.srcPath; string searchPath = XPathTools.Combine(repositoryPath, syncItem.realSearcePath); string syncPath = XPathTools.Combine(repositoryPath, syncItem.realSyncPath); if (XFolderTools.Exists(srcPath) && XFolderTools.Exists(searchPath) && XFolderTools.Exists(syncPath)) { List <string> syncFileList = new List <string>(); List <string> syncFolderList = new List <string>(); if (syncItem.searchMode == AssetSyncItem.SearchMode.Forward) //根据搜索文件找资源 { string srcEx = GetFolderFirstFileExtension(srcPath); XFolderTools.TraverseFiles(searchPath, (filePath) => { string fileKey = null; if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetName) { fileKey = Path.GetFileNameWithoutExtension(filePath); } else if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetPrefix) { fileKey = XStringTools.SplitPathKey(filePath); } string srcFilePath = XPathTools.Combine(srcPath, string.Format("{0}{1}", fileKey, srcEx)); if (XFileTools.Exists(srcFilePath)) { syncFileList.Add(srcFilePath); } }); XFolderTools.TraverseFolder(searchPath, (folderPath) => { string fileKey = null; if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetName) { fileKey = Path.GetFileNameWithoutExtension(folderPath); } else if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetPrefix) { fileKey = XStringTools.SplitPathKey(folderPath); } string srcFolderPath = XPathTools.Combine(srcPath, string.Format("{0}", fileKey)); if (XFolderTools.Exists(srcFolderPath)) { syncFolderList.Add(srcFolderPath); } }); } else if (syncItem.searchMode == AssetSyncItem.SearchMode.Reverse) //根据资源匹对文件 { XFolderTools.TraverseFiles(srcPath, (filePath) => { string fileKey = null; if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetName) { fileKey = Path.GetFileNameWithoutExtension(filePath); } else if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetPrefix) { fileKey = XStringTools.SplitPathKey(filePath); } string searchFilePath = XPathTools.Combine(searchPath, string.Format("{0}", fileKey)); if (XFileTools.Exists(searchFilePath)) { syncFileList.Add(filePath); } }); XFolderTools.TraverseFolder(srcPath, (folderPath) => { string fileKey = null; if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetName) { fileKey = Path.GetFileNameWithoutExtension(folderPath); } else if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetPrefix) { fileKey = XStringTools.SplitPathKey(folderPath); } string searchFilePath = XPathTools.Combine(searchPath, string.Format("{0}", fileKey)); if (XFileTools.Exists(searchFilePath)) { syncFolderList.Add(folderPath); } }); } HashSet <string> syncFileDict = new HashSet <string>(); foreach (var syncSrcFile in syncFileList) { //把文件拷贝到同步目录 string syncFileName = Path.GetFileName(syncSrcFile); string syncDestPath = XPathTools.Combine(syncPath, syncFileName); XFileTools.Delete(syncDestPath); XFileTools.Copy(syncSrcFile, syncDestPath); if (!syncFileDict.Contains(syncDestPath)) { syncFileDict.Add(syncDestPath); } } HashSet <string> syncFolderDict = new HashSet <string>(); foreach (var syncSrcFolder in syncFolderList) { //把文件拷贝到同步目录 string syncFileName = Path.GetFileName(syncSrcFolder); string syncDestPath = XPathTools.Combine(syncPath, syncFileName); XFolderTools.DeleteDirectory(syncDestPath, true); XFolderTools.CopyDirectory(syncSrcFolder, syncDestPath); if (!syncFolderDict.Contains(syncDestPath)) { syncFolderDict.Add(syncDestPath); } } //移除不在同步的文件 XFolderTools.TraverseFiles(syncPath, (syncFullPath) => { if (!syncFileDict.Contains(syncFullPath)) { XFileTools.Delete(syncFullPath); } }); XFolderTools.TraverseFolder(syncPath, (syncFullPath) => { if (!syncFolderDict.Contains(syncFullPath)) { XFolderTools.DeleteDirectory(syncFullPath, true); } }); } } } }
private void DoEnd() { //处理无效的Checkfile文件 string checkfileFolderPath = AssetProcesserConfiger.GetInstance().GetCheckfileSaveFolderPath(_progresersName); //TODO:这里如果全部放到一个路径下,会被别的干扰到了 bool isUseGUID = AssetProcesserConfiger.GetInstance().useGUID4SaveCheckfileName; bool createFolderOrAddSuffix = AssetProcesserConfiger.GetInstance().createFolderOrAddSuffix; XFolderTools.TraverseFiles(checkfileFolderPath, (fullPath) => { string exName = Path.GetExtension(fullPath).ToLower(); if (exName.Contains("meta")) { return; } string realPath = XPathTools.GetRelativePath(fullPath); //路径做Key,有的资源可能名字相同 string realPathLow = realPath.ToLower(); if (isUseGUID) { string srcPath = AssetDatabase.GUIDToAssetPath(realPath); if (string.IsNullOrEmpty(srcPath) || !_assetMap.ContainsKey(realPathLow)) { XFileTools.Delete(fullPath); } } else { bool canDelete = true; if (!createFolderOrAddSuffix) { string fileNameWithoutEx = Path.GetFileNameWithoutExtension(realPath); if (!fileNameWithoutEx.EndsWith(_progresersName)) { canDelete = false; } } if (canDelete && !_checkfilePath2srcAssetPath.ContainsKey(realPath)) { XFileTools.Delete(fullPath); } } }); //处理无效输出文件 string outputFolderPath = AssetProcesserConfiger.GetInstance().GetProcessSaveFolderPath(_progresersName); XFolderTools.TraverseFolder(outputFolderPath, (fullPath) => { string realPath = XPathTools.GetRelativePath(fullPath); string checkKey1 = Path.GetFileNameWithoutExtension(fullPath); string checkKey2 = XStringTools.SplitPathKey(fullPath); //但凡在名字上有点关系都移除,多重key检测 if (!_processPath2srcAssetPath.ContainsKey(checkKey1) && !_processPath2srcAssetPath.ContainsKey(checkKey2) && !_processPath2srcAssetPath.ContainsKey(realPath)) { XFolderTools.DeleteDirectory(fullPath, true); } }); XFolderTools.TraverseFiles(outputFolderPath, (fullPath) => { string exName = Path.GetExtension(fullPath).ToLower(); if (exName.Contains("meta")) { return; } string realPath = XPathTools.GetRelativePath(fullPath); //路径做Key,有的资源可能名字相同 string checkKey1 = Path.GetFileNameWithoutExtension(fullPath); string checkKey2 = XStringTools.SplitPathKey(fullPath); //但凡在名字上有点关系都移除,多重key检测 if (!_processPath2srcAssetPath.ContainsKey(checkKey1) && !_processPath2srcAssetPath.ContainsKey(checkKey2) && !_processPath2srcAssetPath.ContainsKey(realPath)) { XFileTools.Delete(fullPath); } }); OnEnd(); }
static void BuildAssembly(bool wait) { for (int i = 0; i < AssembliesToolsConfig.GetInstance().buildPathList.Count; i++) { var buildInfo = AssembliesToolsConfig.GetInstance().buildPathList[i]; if (!string.IsNullOrEmpty(buildInfo.srcPath) && !string.IsNullOrEmpty(buildInfo.buildPath) && !string.IsNullOrEmpty(buildInfo.projectPath)) { bool[] editorFlags = { true, true, true, true }; List <string> csFilePaths = new List <string>(); XFolderTools.TraverseFiles(buildInfo.srcPath, (string fullPath) => { if (Path.GetExtension(fullPath) == ".cs") { csFilePaths.Add(fullPath); } }, true); string srcPathName = Path.GetFileNameWithoutExtension(buildInfo.srcPath); string outputAssembly = XPathTools.Combine(buildInfo.buildPath, string.Format("{0}.dll", srcPathName)); string assemblyProjectPath = XPathTools.Combine(buildInfo.projectPath, string.Format("{0}.dll", srcPathName)); if (csFilePaths.Count > 0) { if (!XFolderTools.Exists(buildInfo.buildPath)) { XFolderTools.CreateDirectory(buildInfo.buildPath); } if (!XFolderTools.Exists(buildInfo.projectPath)) { XFolderTools.CreateDirectory(buildInfo.projectPath); } bool editorFlag = editorFlags[i]; var assemblyBuilder = new AssemblyBuilder(outputAssembly, csFilePaths.ToArray()); // Exclude a reference to the copy of the assembly in the Assets folder, if any. assemblyBuilder.excludeReferences = new string[] { assemblyProjectPath }; if (editorFlag) { assemblyBuilder.flags = AssemblyBuilderFlags.EditorAssembly; } // Called on main thread assemblyBuilder.buildStarted += delegate(string assemblyPath) { Debug.LogFormat("Assembly build started for {0}", assemblyPath); }; // Called on main thread assemblyBuilder.buildFinished += delegate(string assemblyPath, CompilerMessage[] compilerMessages) { foreach (var v in compilerMessages) { if (v.type == CompilerMessageType.Error) { Debug.LogError(v.message); } else { Debug.LogWarning(v.message); } } var errorCount = compilerMessages.Count(m => m.type == CompilerMessageType.Error); var warningCount = compilerMessages.Count(m => m.type == CompilerMessageType.Warning); Debug.LogFormat("Assembly build finished for {0}", assemblyPath); Debug.LogFormat("Warnings: {0} - Errors: {0}", errorCount, warningCount); if (errorCount == 0) { File.Copy(outputAssembly, assemblyProjectPath, true); AssetDatabase.ImportAsset(assemblyProjectPath); } }; // Start build of assembly if (!assemblyBuilder.Build()) { Debug.LogErrorFormat("Failed to start build of assembly {0}!", assemblyBuilder.assemblyPath); return; } if (wait) { while (assemblyBuilder.status != AssemblyBuilderStatus.Finished) { System.Threading.Thread.Sleep(10); } } } else { XFileTools.Delete(assemblyProjectPath); continue; } } } }