This commit is contained in:
bob
2025-06-05 15:39:47 +08:00
parent 55f49e1af7
commit f9c0975f10
50 changed files with 575 additions and 51 deletions

View File

@@ -6,6 +6,7 @@ using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using ExcelDataReader;
using NBC;
using Newtonsoft.Json;
@@ -18,12 +19,15 @@ namespace NBF
{
public static class ExcelToJsonWindow
{
#region
public static void GenConfig(bool showMessageBox = true)
{
CfgEditorUtil.GenConfigScripts();
GenConfig(Application.dataPath + "/../Config", showMessageBox);
}
public static void GenConfig(string path, bool showMessageBox = false)
{
List<string> list = new List<string>();
@@ -54,7 +58,6 @@ namespace NBF
private static void BuildAsset()
{
//Application.dataPath
var json = JsonConvert.SerializeObject(AllJsonData, Formatting.Indented, new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
@@ -80,21 +83,10 @@ namespace NBF
}
}
// 将路径中的所有反斜杠转换为正斜杠
// string normalizedAbsolutePath = savePath.Replace("\\", "/");
// string normalizedDataPath = Application.dataPath.Replace("\\", "/");
// string relativePath = normalizedAbsolutePath.Replace(normalizedDataPath, "");
// ConfigAssets.SavePath
// var relativePath = "Assets/ResRaw/config/ConfigAssets.asset";
//$"Assets/Resources/Config/ConfigAssets.asset";
var relativePath = ConfigAssets.SavePath;
var asset = EditorUtils.GetOrCreateAsset<ConfigAssets>(relativePath);
var types = Reflection.GetAllNonAbstractDerivedTypes<ConfigBase>();
foreach (var type in types)
{
@@ -115,6 +107,48 @@ namespace NBF
AssetDatabase.Refresh();
}
#endregion
#region
public static void GenLanguage()
{
var path = Application.dataPath + "/../Config/language";
List<string> list = new List<string>();
GetFiles(path, fileList: ref list);
AllJsonData.Clear();
Stopwatch s = Stopwatch.StartNew();
ReadExcel(list.ToArray());
var savePath = Path.Combine(Application.dataPath, "Resources/config/language.json");
BuildJson(savePath);
s.Stop();
Debug.Log($"导多语言完成,耗时{(s.ElapsedMilliseconds / 1000f):.00}秒");
AssetDatabase.Refresh();
}
private static void BuildJson(string savaPath)
{
var json = JsonConvert.SerializeObject(AllJsonData, Formatting.Indented, new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
SaveJson(savaPath, json);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
#endregion
#region
private static void GetFiles(string path, ref List<string> fileList)
@@ -136,8 +170,25 @@ namespace NBF
}
}
#endregion
private static void SaveJson(string jsonPath, string json)
{
try
{
if (File.Exists(jsonPath))
{
File.Delete(jsonPath);
}
File.WriteAllBytes(jsonPath, Encoding.UTF8.GetBytes(json));
}
catch (Exception e)
{
// Console.WriteLine(e);
// throw;
}
}
#endregion
#region Excel读取