obsidian/笔记文件/2.笔记/unity内部移动文件.md
2025-03-26 00:02:56 +08:00

1.8 KiB
Raw Permalink Blame History

#unity/日常积累

先通过python生成对应的csv配置表文件具体代码可参考 Resourceraw

然后读csv表通过unity内部的移动文件接口就可以完成unity的文件移动核心代码是这句

ret = AssetDatabase.MoveAsset(cells[1], cells[2]);

整体代码:

using UnityEditor;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System;

public class AssetMoveEditor : EditorWindow
{
    
    private static Dictionary<string,string> PathDic = new Dictionary<string, string>();
    private static List<string> styleList = new List<string>
    {
        "fbx",
        "mat"
    };
    
    

    private static void CSV(string table)
    {
        PathDic.Clear();
        string[] lines = table.Split(new [] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);

        int current = 1;
        string ret;
        while (current < lines.Length)
        {
            string[] cells = lines[current].Split(',');
            ret = AssetDatabase.MoveAsset(cells[1], cells[2]);
            if (ret != "")
            {
                Debug.Log("ret:" + ret);
            }
            ++current;
        }

    }
    
    [MenuItem("美术工具/Raw目录改造", false, 1)]
    private static void tempCheck()
    {
        
        string csvConfig;
        string path;

        for (int j = 0; j < styleList.Count; j++)
        {
            for (int i = 1; i < 4; i++)
            {
                path = $"Assets/ResourcesRaw/CommonRegion/Skins/InGameEmotion/{styleList[j]}_{i}.csv";
                if (File.Exists(path))
                {
                    csvConfig = File.ReadAllText(path);
                    CSV(csvConfig);
                }
            }
        }
        
        
    }

}