2025-01-02 19:36:17 +08:00
|
|
|
|
using System.IO;
|
2025-01-02 12:15:45 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
namespace CG.UTility
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class ExcelTools
|
|
|
|
|
|
{
|
2025-01-02 19:36:17 +08:00
|
|
|
|
#if UNITY_EDITOR
|
2025-01-02 12:15:45 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 加载Excel
|
|
|
|
|
|
/// </summary>
|
2025-01-02 19:36:17 +08:00
|
|
|
|
[UnityEditor.MenuItem("Tools/ExcelTools", false, 4)]
|
2025-01-02 12:15:45 +08:00
|
|
|
|
private static void LoadExcel()
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] excelList = Directory.GetFiles(Application.streamingAssetsPath + ConstCtrl.EXCEL_PATH, "*.xlsx");
|
|
|
|
|
|
for (int i = 0; i < excelList.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
Convert(excelList[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-01-02 19:36:17 +08:00
|
|
|
|
#endif
|
2025-01-02 12:15:45 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 转换Excel文件
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private static void Convert(string excelFile)
|
|
|
|
|
|
{
|
|
|
|
|
|
//构造Excel工具类
|
|
|
|
|
|
ExcelUtility excel = new ExcelUtility(excelFile);
|
2025-01-02 19:36:17 +08:00
|
|
|
|
excel.ConvertToJson(Application.streamingAssetsPath + ConstCtrl.JSON_PATH+ Path.GetFileNameWithoutExtension(excelFile)+".txt", new UTF8Encoding(false));
|
|
|
|
|
|
excel.ConvertToCSharp(Application.streamingAssetsPath + ConstCtrl.CSHARP_PATH + Path.GetFileNameWithoutExtension(excelFile) + ".cs", new UTF8Encoding(false));
|
|
|
|
|
|
#if UNITY_EDITOR
|
2025-01-02 12:15:45 +08:00
|
|
|
|
//刷新本地资源
|
2025-01-02 19:36:17 +08:00
|
|
|
|
UnityEditor.AssetDatabase.Refresh();
|
|
|
|
|
|
#endif
|
2025-01-02 12:15:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|