1.8 KiB
1.8 KiB
#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);
}
}
}
}
}