如果是编辑器不使用运行时的话,直接使用UnityEditor下的API即可

FileUtil.CopyFileOrDirectory

如果是运行时

///

/// 文件夹拷贝

///

/// 源路径

/// 目标路径

private void CopyFolder(string sourcePath, string destPath)

{

if (Directory.Exists(sourcePath))

{

if (!Directory.Exists(destPath))

{

try

{

Directory.CreateDirectory(destPath);

}

catch (Exception ex)

{

Debug.LogError("创建失败");

}

}

List files = new List(Directory.GetFiles(sourcePath));

files.ForEach(c =>

{

//排除meta文件

if (!c.EndsWith(".meta"))

{

string destFile = Path.Combine(destPath, Path.GetFileName(c));

File.Copy(c, destFile, true);

}

});

List folders = new List(Directory.GetDirectories(sourcePath));

folders.ForEach(c =>

{

string destDir = Path.Combine(destPath,Path.GetFileName(c));

CopyFolder(c, destDir);

});

}

else

{

Debug.LogError("源目录不存在");

}

}

 

 

 

精彩链接

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。