微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

unity文件夹复制

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

FileUtil.copyFileOrDirectory

如果是运行时

    /// <summary>
    /// 文件夹拷贝
    /// </summary>
    /// <param name="sourcePath">源路径</param>
    /// <param name="destPath">目标路径</param>
    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<string> files = new List<string>(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<string> folders = new List<string>(Directory.GetDirectories(sourcePath));
            folders.ForEach(c =>
            {
                string destDir = Path.Combine(destPath,Path.GetFileName(c));
                copyFolder(c, destDir);
            });
        }
        else
        {
            Debug.LogError("源目录不存在");
        }
    }

 

 

 


                
                                 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐