一键生成配置表
由于发布之后需要从Resources文件对应的Config下读取配置表,而且需将.csv文件加上后缀bytes(速度快),为了避免多次操作导致,出现未知错误,所以交给计算机操作。
using UnityEngine;
using UnityEditor;
using System.IO;
public class EasyEditor : Editor
{
//把配置文件放到Resources目录下
[MenuItem("Custom/ConfigToResources")]
public static void ConfigToResources()
{
//寻找已经保存好的.csv文件
var srcPath = Application.dataPath + "/../Config/";
//应该存储的资源路径
var dstPath = Application.dataPath + "/Resources/Config/";
//删除目标文件里的所有的子文件
Directory.Delete(dstPath,true);
//如果Resources下没有Config文件 则创建
Directory.CreateDirectory(dstPath);
//找到每个.csv文件对应的路径
foreach (var filePath in Directory.GetFiles(srcPath))
{
//取出对应的每个表的文件名
var fileName = filePath.Substring(filePath.LastIndexOf('/') + 1);
//复制文件 到目标文件夹内 并在每个文件名加上后缀.bytes
File.Copy(filePath, dstPath + fileName + ".bytes",true);
}
//刷新
AssetDatabase.Refresh();
Debug.Log("配置文件赋值完毕");
}
}
若要读取配置表,请配合读取配置表一起食用,风味更佳。