//相对与版本库下层路径 public string GetCheckFolderRelativePath(string fullPath) { if (string.IsNullOrEmpty(repositoryRootPath)) { return(""); } if (string.IsNullOrEmpty(fullPath)) { return(""); } if (fullPath.IndexOf(repositoryRootPath) < 0) { return(""); } fullPath = XPathTools.NormalizePath(fullPath); string relaPath = fullPath.Replace(repositoryRootPath, ""); if (relaPath.StartsWith("/")) { relaPath = relaPath.Remove(0, 1); } int startPos = relaPath.IndexOf("/"); if (startPos > 0) { relaPath = relaPath.Remove(0, startPos + 1); } return(relaPath); }
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(); } }
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); }
private void RefreshAssetList() { _assetList.Clear(); foreach (var path in _assetFolderList) { string key = XPathTools.SubRelativePath(_assetFolderPath, path); string fileName = Path.GetFileName(path); if (_configDict != null) { if (_configDict.ContainsKey(key)) { continue; } } string searchKey = _srcSearchTextField.GetText(); if (!string.IsNullOrEmpty(searchKey)) { if (fileName.IndexOf(searchKey) < 0) { continue; } } var item = new AssetItem(); item.path = path; _assetList.Add(item); } }
public void Freeze(int version) { if (version <= 0) { return; } var repositoryRoot = AssetSyncConfiger.GetInstance().GetRepositoryRootPath(); if (string.IsNullOrEmpty(repositoryRoot)) { return; } var syncItems = AssetSyncConfiger.GetInstance().syncItems; if (syncItems == null || syncItems.Count <= 0) { return; } string versionFolderName = string.Format("{0}", version); string repositoryPath = XPathTools.Combine(repositoryRoot, versionFolderName); foreach (var syncItem in syncItems) { string destPath = XPathTools.Combine(repositoryPath, syncItem.realSearcePath); if (XFolderTools.Exists(destPath)) { XFolderTools.DeleteDirectory(destPath, true); } } }
/// static void CreateEditor(string assetPath) { string selectRootPath = XPathTools.GetFileRootPath(assetPath); // 处理开始 var scene = EditorSceneManager.OpenScene(GetEditorPath()); if (scene != null) { // 保存新场景 string savePath = XPathTools.Combine(selectRootPath, string.Format(saveDefaultName)); savePath = XPathTools.GetUniquePath(savePath); //做工,弄一个主角 EditorSceneManager.SaveScene(scene, savePath); } else { Debug.LogWarning("编辑器路径错误"); } }
public static string[] FindReferences(string assetPath, string searchPath = null, string[] searchSuffix = null) { searchPath = string.IsNullOrEmpty(searchPath) ? Application.dataPath : searchPath; searchSuffix = searchSuffix != null ? searchSuffix : SERIALIZABLE_FILE_SUFFIX; string assetPathLow = XPathTools.GetRelativePath(assetPath.ToLower()); string[] files = Directory.GetFiles(searchPath, "*.*", SearchOption.AllDirectories) .Where(s => searchSuffix.Contains(Path.GetExtension(s).ToLower())) .ToArray(); HashSet <string> refDict = new HashSet <string>(); foreach (var file in files) { string relativePath = XPathTools.GetRelativePath(file); string[] dps = AssetDatabase.GetDependencies(relativePath); foreach (string path in dps) { string pathLow = path.ToLower(); if (pathLow.Contains(assetPathLow)) { if (!refDict.Contains(path)) { refDict.Add(path); } } } } return(refDict.ToArray()); }
public string GetCheckfileFloderPath() { string newCheckfileFolderName = string.IsNullOrEmpty(checkfileFolderName) ? DEFAULT_MD5_FOLDER_NAME : checkfileFolderName; string checkfileFolderPath = XPathTools.Combine(GetOutputFolderPath(), newCheckfileFolderName); return(checkfileFolderPath); }
/// <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()); }
/// <summary> /// 从对应的json文件生成精灵帧(DragonBones 5.5) /// </summary> /// <param name="assetPath">图集路径</param> public static void SetupSpriteFrameFromDBJsonFile(string assetPath) { string assetFileNonExtName = Path.GetFileNameWithoutExtension(assetPath); string assetRootPath = Path.GetDirectoryName(assetPath); //查看是否有对应的json文件 string jsonFilePath = XPathTools.Combine(assetRootPath, string.Format("{0}.json", assetFileNonExtName)); if (!XFileTools.Exists(jsonFilePath)) { Debug.LogWarning("找不到DragonBones 5.5图集Json文件"); return; } TextureImporter importer = LoadImporterFromTextureFile(assetPath); if (importer) { var jsonFile = AssetDatabase.LoadAssetAtPath(jsonFilePath, typeof(TextAsset)) as TextAsset; if (jsonFile == null) { return; } var atlas = JsonUtility.FromJson <DBSheet>(jsonFile.text); if (atlas != null) { if (atlas.SubTexture.Count > 0) { List <SpriteMetaData> spriteDataList = new List <SpriteMetaData>(); foreach (var frameData in atlas.SubTexture) { SpriteMetaData md = new SpriteMetaData(); int width = frameData.width; int height = frameData.height; int x = frameData.x; int y = atlas.height - height - frameData.y;//TexturePacker以左上为原点,Unity以左下为原点 md.rect = new Rect(x, y, width, height); md.pivot = md.rect.center; md.name = frameData.name; spriteDataList.Add(md); } importer.textureType = TextureImporterType.Sprite; //设置为精灵图集 importer.spriteImportMode = SpriteImportMode.Multiple; //设置为多个 importer.spritesheet = spriteDataList.ToArray(); importer.SaveAndReimport(); } Debug.Log(string.Format("图集:{0},共生成{1}帧", atlas.name, atlas.SubTexture.Count)); } } }
public string GetCheckfileSaveFolderPath(string progressName) { string checkfileFolderPath = GetCheckfileFloderPath(); string checkfileSaveParentPath = checkfileFolderPath; if (createFolderOrAddSuffix) { checkfileSaveParentPath = XPathTools.Combine(checkfileFolderPath, progressName); } return(checkfileSaveParentPath); }
///////////// private string GetCheckfilePath(string srcPath) { string checkfileSavePath = AssetProcesserConfiger.GetInstance().GetCheckfileSavePath(_progresersName, srcPath, ".asset"); var outName = OnCheckFileName(srcPath); if (!string.IsNullOrEmpty(outName)) { string exName = Path.GetExtension(checkfileSavePath); string parentPath = Path.GetDirectoryName(checkfileSavePath); checkfileSavePath = XPathTools.Combine(parentPath, string.Format("{0}{1}", outName, exName)); } return(checkfileSavePath); }
public string GetProcessFloderPath() { string processFolderPath; if (string.IsNullOrEmpty(processFolderName)) { processFolderPath = GetOutputFolderPath(); } else { processFolderPath = XPathTools.Combine(GetOutputFolderPath(), processFolderName); } return(processFolderPath); }
public static void GenerateDBJsonFromDBTextureFile(string assetPath, string savePath = "") { string assetFileNonExtName = Path.GetFileNameWithoutExtension(assetPath); string assetRootPath = Path.GetDirectoryName(assetPath); TextureImporter importer = LoadImporterFromTextureFile(assetPath); if (importer) { //判断是否是精灵图集 if (!(importer.textureType == TextureImporterType.Sprite && importer.spriteImportMode == SpriteImportMode.Multiple)) { return; } Texture texture = AssetDatabase.LoadAssetAtPath <Texture>(assetPath); DBSheet sheet = new DBSheet(); sheet.name = assetFileNonExtName; sheet.imagePath = Path.GetFileName(assetPath); sheet.width = texture.width; sheet.height = texture.height; //获取所有精灵帧 Object[] sheetObjs = AssetDatabase.LoadAllAssetsAtPath(assetPath); for (int i = 1; i < sheetObjs.Length; i++) //第一张不是精灵帧 { Sprite sprite = sheetObjs[i] as Sprite; Rect rect = sprite.rect; DBSheet.DBFrame frame = new DBSheet.DBFrame(); frame.name = sprite.name; frame.width = (int)rect.width; frame.height = (int)rect.height; frame.x = (int)rect.x; frame.y = (int)(sheet.height - frame.height - rect.y); sheet.SubTexture.Add(frame); } var jsonStr = JsonUtility.ToJson(sheet, true); if (savePath == "") { savePath = XPathTools.Combine(assetRootPath, string.Format("{0}.json", assetFileNonExtName)); } File.WriteAllText(savePath, jsonStr, Encoding.UTF8); AssetDatabase.Refresh(); } }
public string GetBuildBundleShareName(string assetPath) { if (!string.IsNullOrEmpty(shareBundleName)) { return(GetFormatBundleName(shareBundleName, assetPath)); } else { assetPath = XPathTools.GetRelativePath(assetPath); string newBundleSuffix = string.IsNullOrEmpty(bundleSuffix) ? DEFAULT_BUILD_SUFFFIX : bundleSuffix; string assetNameLow = Path.GetFileNameWithoutExtension(assetPath).ToLower(); string assetFlatPath = GetFlatPath(assetPath); string bundleName = string.Format("share/{0}_{1}{2}", assetFlatPath, assetNameLow, newBundleSuffix); return(bundleName.ToLower()); } }
public string GetBuildBundleCommonName(string builderName, string assetPath, bool isCommonKey = false) { string newBundleSuffix = string.IsNullOrEmpty(bundleSuffix) ? DEFAULT_BUILD_SUFFFIX : bundleSuffix; string buildFolderPath = GetBuildFolderPath(builderName); string assetNameNotEx = Path.GetFileNameWithoutExtension(assetPath); string assetFinalName = assetNameNotEx; if (isCommonKey) { assetFinalName = XStringTools.SplitPathKey(assetPath); } string bundleFileName = string.Format("{0}{1}", assetFinalName, newBundleSuffix); string bundleName = XPathTools.Combine(buildFolderPath, bundleFileName); return(bundleName.ToLower()); }
private void AddConfig(string fullPath) { if (string.IsNullOrEmpty(fullPath)) { return; } string relaPath = XPathTools.SubRelativePath(_assetFolderPath, fullPath); _configDict = _configDict ?? new Dictionary <string, ConfigItem>(); ConfigItem newItem = new ConfigItem(); newItem.path = relaPath; _configDict[relaPath] = newItem; }
public List <LeafNodeDictionaryEntry> GetAndRemoveByTagNames(List <String> tags, Boolean DoRemove = true, Boolean Inverse = false) { List <String> ToRemove = new List <string>(); List <LeafNodeDictionaryEntry> output = new List <LeafNodeDictionaryEntry>(); List <Regex> regexList = new List <Regex>(); //foreach (String tag in tags) //{ // Regex r = new Regex(tag + "\\[[\\d]+\\]\\Z"); // regexList.Add(r); //} foreach (var item in items.ToList()) { String nodeName = XPathTools.GetLastNodeNameFromXPath(item.XPath).ToLower(); if (tags.Contains(nodeName) == !Inverse) { ToRemove.Add(item.XPath); output.Add(item); } //Boolean isMatch = false; //foreach (var r in regexList) //{ // if (r.IsMatch(item.XPath)) // { // isMatch = true; // break; // } //} //if (isMatch == !Inverse) //{ //} } if (DoRemove) { RemoveEntriesByXPath(ToRemove); RebuildIndex(); } return(output); }
public string GetFlatPath(string assetPath) { assetPath = XPathTools.GetRelativePath(assetPath); string assetParentPath = Path.GetDirectoryName(assetPath).ToLower(); string relaPath = assetParentPath.Replace("assets", ""); string flatPath = relaPath.Replace("/", "_"); if (!string.IsNullOrEmpty(flatPath)) { string newFlatPath = flatPath.Remove(0, 1); newFlatPath = string.Format("{0}_", newFlatPath); return(newFlatPath); } else { return(""); } }
private static void UpdateReferences() { m_gridDict.Clear(); string assetDir = Application.dataPath; var withoutExtensions = new List <string>() { ".prefab", ".unity", ".mat", ".asset", ".controller", ".playable" }; string[] files = Directory.GetFiles(assetDir, "*.*", SearchOption.AllDirectories) .Where(s => withoutExtensions.Contains(Path.GetExtension(s).ToLower())) .ToArray(); int startIndex = 0; EditorApplication.update = delegate() { string file = files[startIndex]; bool isCancel = EditorUtility.DisplayCancelableProgressBar("匹配资源中", file, (float)startIndex / (float)files.Length); string relativePath = XPathTools.GetRelativePath(file); string[] dps = AssetDatabase.GetDependencies(relativePath); foreach (string path in dps) { if (!m_gridDict.ContainsKey(path)) { m_gridDict.Add(path, new ArrayList()); } ArrayList existFiles = m_gridDict[path]; existFiles.Add(relativePath); } startIndex++; if (isCancel || startIndex >= files.Length) { EditorUtility.ClearProgressBar(); EditorApplication.update = null; startIndex = 0; } }; }
public static Dictionary <string, string[]> GetAllReferences(string searchPath = null, string[] searchSuffix = null) { searchPath = string.IsNullOrEmpty(searchPath) ? Application.dataPath : searchPath; searchSuffix = searchSuffix != null ? searchSuffix : SERIALIZABLE_FILE_SUFFIX; Dictionary <string, HashSet <string> > refSetMap = new Dictionary <string, HashSet <string> >(); string[] files = Directory.GetFiles(searchPath, "*.*", SearchOption.AllDirectories) .Where(s => searchSuffix.Contains(Path.GetExtension(s).ToLower())) .ToArray(); foreach (var file in files) { string relativePath = XPathTools.GetRelativePath(file); string[] dps = AssetDatabase.GetDependencies(relativePath); foreach (string path in dps) { string depRelatPath = XPathTools.GetRelativePath(path); if (depRelatPath.Contains(relativePath)) { if (!refSetMap.ContainsKey(relativePath)) { refSetMap[relativePath] = new HashSet <string>(); } var fileSet = refSetMap[relativePath]; if (!fileSet.Contains(depRelatPath)) { fileSet.Add(path); } } } } Dictionary <string, string[]> refMap = new Dictionary <string, string[]>(); foreach (var kv in refSetMap) { refMap[kv.Key] = kv.Value.ToArray(); } return(refMap); }
//路径条 public static string ShowPathBar(string label, string text, string desc = "Source Folder Path", Func <string, string> callback = null) { EditorGUILayout.BeginHorizontal(); string path = EditorGUILayout.TextField(label, text); if (GUILayout.Button("浏览")) { var selectedFolderPath = EditorUtility.SaveFolderPanel(desc, "Assets", ""); if (!string.IsNullOrEmpty(selectedFolderPath)) { path = XPathTools.GetRelativePath(selectedFolderPath); if (callback != null) { path = callback.Invoke(selectedFolderPath); } } } EditorGUILayout.EndHorizontal(); return(path); }
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 string GetCheckfileSavePath(string progressName, string srcFilePath, string suffix = null) { string outputName = Path.GetFileNameWithoutExtension(srcFilePath); //有些可能是同一个Key,二层Key的 string checkfileSaveParentPath = GetCheckfileSaveFolderPath(progressName); string cehckfileSaveName = outputName; if (!createFolderOrAddSuffix) { if (string.IsNullOrEmpty(suffix)) { cehckfileSaveName = string.Format("{0}_{1}", cehckfileSaveName, progressName); } else { cehckfileSaveName = string.Format("{0}_{1}{2}", cehckfileSaveName, progressName, suffix); } } else { if (string.IsNullOrEmpty(suffix)) { cehckfileSaveName = string.Format("{0}", cehckfileSaveName); } else { cehckfileSaveName = string.Format("{0}{1}", cehckfileSaveName, suffix); } } if (useGUID4SaveCheckfileName) { cehckfileSaveName = AssetDatabase.AssetPathToGUID(srcFilePath); } string md5SavePath = XPathTools.Combine(checkfileSaveParentPath, cehckfileSaveName); return(md5SavePath); }
public string GetExportFolderPath() { string newExportFolder = string.IsNullOrEmpty(exportFolder) ? DEFAULT_EXPORT_PATH : exportFolder; string retExportPath = newExportFolder; if (isCombinePlatformName) { if (targetType == BuildPlatform.Auto) { var buildPlatform = GetBuildPlatform(); string buildPlatformStr = Enum.GetName(typeof(BuildPlatform), buildPlatform); retExportPath = XPathTools.Combine(newExportFolder, buildPlatformStr); } else { string buildPlatformStr = Enum.GetName(typeof(BuildPlatform), targetType); retExportPath = XPathTools.Combine(newExportFolder, buildPlatformStr); } } string normalRetExportPath = XPathTools.NormalizePath(retExportPath); return(normalRetExportPath.ToLower()); }
private List <string> CollectShare() { Dictionary <string, int> refCounts = new Dictionary <string, int>(); foreach (var kv in m_buildAssetMap) { foreach (var fullPath in kv.Value) { string assetPath = XPathTools.GetRelativePath(fullPath); string[] dps = AssetBuildRelationship.GetDependencies(assetPath); foreach (var dp in dps) { if (refCounts.TryGetValue(dp, out var refCount)) { refCounts[dp] = refCount + 1; } else { refCounts.Add(dp, 1); } } } } List <string> shareAssetList = new List <string>(); foreach (var refKV in refCounts) { if (refKV.Value > 1) { shareAssetList.Add(refKV.Key); } } return(shareAssetList); }
public List <string> GetFileList() { if (m_files == null) { m_files = new List <string>(); var files = OnFiles(); if (files == null || files.Length <= 0) { return(m_files); } foreach (var fullPath in files) { if (string.IsNullOrEmpty(fullPath)) { continue; } string assetPath = XPathTools.GetRelativePath(fullPath); m_files.Add(assetPath); } } return(m_files); }
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(); }
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); } }); } } } }
protected virtual string[] GetDependencies(string assetPath) { assetPath = XPathTools.GetRelativePath(assetPath); return(AssetBuildRelationship.GetDependencies(assetPath)); }