使用UnityEditor.FileUtil.CopyFileOrDirectory代替System.IO.File.Copy

pull/56/head
xiewen 2025-07-30 13:54:02 +08:00
parent 73654e76d2
commit 12969d32b5
1 changed files with 1 additions and 21 deletions

View File

@ -102,26 +102,6 @@ namespace HybridCLR.Editor.Installer
}
Directory.CreateDirectory(dir);
}
private static void CopyWithCheckLongFile(string srcFile, string dstFile)
{
var maxPathLength = 255;
#if UNITY_EDITOR_OSX
maxPathLength = 1024;
#endif
if (srcFile.Length > maxPathLength)
{
UnityEngine.Debug.LogError($"srcFile:{srcFile} path is too long. skip copy!");
return;
}
if (dstFile.Length > maxPathLength)
{
UnityEngine.Debug.LogError($"dstFile:{dstFile} path is too long. skip copy!");
return;
}
File.Copy(srcFile, dstFile);
}
public static void CopyDir(string src, string dst, bool log = false)
{
if (log)
@ -132,7 +112,7 @@ namespace HybridCLR.Editor.Installer
Directory.CreateDirectory(dst);
foreach(var file in Directory.GetFiles(src))
{
CopyWithCheckLongFile(file, $"{dst}/{Path.GetFileName(file)}");
UnityEditor.FileUtil.CopyFileOrDirectory(file, $"{dst}/{Path.GetFileName(file)}");
}
foreach(var subDir in Directory.GetDirectories(src))
{