diff --git a/Editor/IO/Files/CopyFilesToDirectory.cs b/Editor/IO/Files/CopyFilesToDirectory.cs new file mode 100644 index 0000000..b900541 --- /dev/null +++ b/Editor/IO/Files/CopyFilesToDirectory.cs @@ -0,0 +1,46 @@ +using System.IO; +using System.Threading.Tasks; +using UnityEditor; +using UnityEngine; + +namespace UniTools.Build +{ + [CreateAssetMenu( + fileName = nameof(CopyFilesToDirectory), + menuName = MenuPaths.IO + nameof(CopyFilesToDirectory) + )] + public sealed class CopyFilesToDirectory : BuildStep + { + [SerializeField] private PathProperty m_sourceDirectory = default; + [SerializeField] private PathProperty[] m_sourceFiles = default; + [SerializeField] private PathProperty m_destinationDirectory = default; + + public override async Task Execute() + { + var sourceFolder = m_sourceDirectory.ToString(); + var hasNoSourceFolder = string.IsNullOrEmpty(sourceFolder); + var destinationFolder = m_destinationDirectory.ToString(); + + if (!hasNoSourceFolder && !Directory.Exists(sourceFolder)) + { + throw new DirectoryNotFoundException($"Source folder: {sourceFolder} does not exist!"); + } + if (!Directory.Exists(destinationFolder)) + { + throw new DirectoryNotFoundException($"Destination folder {destinationFolder} does not exist!"); + } + + foreach (var sourceFile in m_sourceFiles) + { + var filePath = sourceFile.ToString(); + var fileName = Path.GetFileName(filePath); + var source = hasNoSourceFolder ? filePath : Path.Combine(sourceFolder, filePath); + var destination = Path.Combine(destinationFolder, fileName); + FileUtil.DeleteFileOrDirectory(destination); + FileUtil.CopyFileOrDirectory(source, destination); + } + + await Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/Editor/IO/Files/CopyFilesToDirectory.cs.meta b/Editor/IO/Files/CopyFilesToDirectory.cs.meta new file mode 100644 index 0000000..c36fd7c --- /dev/null +++ b/Editor/IO/Files/CopyFilesToDirectory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3077c4aac47fe402499d5d4347811199 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: