【无标题】- 自用代码 优化资源时常用的备份一个目录

发布时间:2024年01月08日

右键,备份并删除

using System.IO;
using UnityEditor;
using UnityEngine;
/// <summary>
/// 删除字体,减少资源等优化功能,并且可以备份
/// </summary>
public class BackUpYouhuaWindow : EditorWindow
{
    [MenuItem("Assets/备份并删除")]
    public static void BackupAndDeleteFile()
    {
        if (EditorUtility.DisplayDialog("", "确认删除?还原功能没做,请谨慎", "Ok","Cancel"))
        {
            DoBackupAndDelete();
        }
    }
    static void DoBackupAndDelete()
    {

        if (Selection.count == 0) return;
        foreach (var obj in Selection.objects)
        {
            DoBackupAndDeleteOneByOne(obj);
        }
        AssetDatabase.Refresh();
    }

    static void DoBackupAndDeleteOneByOne(Object obj)
    {
        //注意i需要连.meta文件一起备份
        string path = AssetDatabase.GetAssetPath(obj);
        string destPath = Application.dataPath + "/../OutputBk/" + path;
        //TODO:检测文件是否存在
        var folder = Path.GetDirectoryName(destPath);

        string pathMeta = path + ".meta";
        
        string destMeta = Application.dataPath +  "/../OutputBk/" + pathMeta;
        if (Directory.Exists(folder) == false)
            Directory.CreateDirectory(folder);
        
        
        FileUtil.CopyFileOrDirectory(pathMeta,destMeta);
        FileUtil.CopyFileOrDirectory(path,destPath);
        FileUtil.DeleteFileOrDirectory(path);
        
    }

}

文章来源:https://blog.csdn.net/avi9111/article/details/126833890
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。