private static bool ValidatePasteAssets() { for (int i = 0; i < ProjectCopyAssets.copyAssetPaths.Count; i++) { if (File.Exists(ProjectCopyAssets.copyAssetPaths[i]) == false && Directory.Exists(ProjectCopyAssets.copyAssetPaths[i]) == false) { ProjectCopyAssets.copyAssetPaths.RemoveAt(i--); ProjectCopyAssets.GUIDs.RemoveAt(i--); } } return(ProjectCopyAssets.copyAssetPaths.Count > 0 && ProjectCopyAssets.GetDestinationPath() != null); }
private static void PasteAssets(MenuCommand menuCommand) { string destination = ProjectCopyAssets.GetDestinationPath(); if (File.Exists(destination) == true) { destination = Path.GetDirectoryName(destination); } if (Directory.Exists(destination) == true) { for (int i = 0; i < ProjectCopyAssets.copyAssetPaths.Count; i++) { string fullPath = Path.Combine(destination, Path.GetFileName(ProjectCopyAssets.copyAssetPaths[i])); bool incrementalCopy = false; if (File.Exists(fullPath) == true) { incrementalCopy = true; } if (incrementalCopy == false) { if (ProjectCopyAssets.cut == false) { if (AssetDatabase.CopyAsset(ProjectCopyAssets.copyAssetPaths[i], fullPath) == false) { InternalNGDebug.Log("Copy of \"" + ProjectCopyAssets.copyAssetPaths[i] + "\" into \"" + destination + "\" failed."); } } else { string error = AssetDatabase.MoveAsset(ProjectCopyAssets.copyAssetPaths[i], fullPath); if (string.IsNullOrEmpty(error) == false) { InternalNGDebug.Log(error); } else { ProjectCopyAssets.copyAssetPaths[i] = fullPath; } } } else { string filename = Path.GetFileNameWithoutExtension(ProjectCopyAssets.copyAssetPaths[i]); string extension = Path.GetExtension(ProjectCopyAssets.copyAssetPaths[i]); int n = 0; int j = filename.Length - 1; // Extract increment if it exists. while (j >= 0 && '0' <= filename[j] && filename[j] <= '9') { n = n * 10 + filename[j] - '0'; --j; } if (n > 0) { filename = filename.Substring(0, j + 1); } else { n = 1; filename += ' '; } fullPath = Path.Combine(destination, filename + n + extension); while (File.Exists(fullPath) == true) { ++n; fullPath = Path.Combine(destination, filename + n + extension); } if (ProjectCopyAssets.cut == false) { if (AssetDatabase.CopyAsset(ProjectCopyAssets.copyAssetPaths[i], fullPath) == false) { InternalNGDebug.Log("Copy of \"" + ProjectCopyAssets.copyAssetPaths[i] + "\" into \"" + destination + "\" failed."); } } else { string error = AssetDatabase.MoveAsset(ProjectCopyAssets.copyAssetPaths[i], fullPath); if (string.IsNullOrEmpty(error) == false) { InternalNGDebug.Log(error); } ProjectCopyAssets.copyAssetPaths[i] = fullPath; } } AssetDatabase.Refresh(); } } }