NLDClient-yudde/ProjectNLD/Assets/Editor/Tools/AutoConfig/MixKeyTool/MixKeyGenJson.cs

68 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using AutoConfig;
using Newtonsoft.Json;
public class MixKeyGenJson
{
public static Dictionary<string, string> MixKeyDic = new();
public static readonly string JsonPath = "Assets/Config/MixKey/MixKeyConfig.json";
public static bool IsGenJsonProcess;
private static void _LoadMixKeyDic()
{
MixKeyDic.Clear();
var keyList = ExcelRead.StringCfgMixKeyList;
var valList = ExcelRead.StringCfgMixValueList;
if (keyList != null)
{
if (valList != null)
{
for (int i = 0; i < keyList.Count; i++)
{
MixKeyDic.Add(keyList[i], valList[i]);
}
}
}
}
private static string _GenJsonStr()
{
if (MixKeyDic.Count > 0)
{
var jsonStr = JsonConvert.SerializeObject(MixKeyDic);
return jsonStr;
}
DebugUtil.LogError("生成Json时出错MixKeyDic为空");
return null;
}
public static void GenMixKeyJsonFile()
{
try
{
_LoadMixKeyDic();
var jsonStr = _GenJsonStr();
if (jsonStr == null)
{
throw new Exception();
}
File.WriteAllText(JsonPath, jsonStr, System.Text.Encoding.UTF8);
DebugUtil.Log("生成MixKey配置成功");
}
catch (Exception e)
{
DebugUtil.LogError(e);
DebugUtil.Log("生成MixKey配置失败");
}
finally
{
IsGenJsonProcess = false;
}
}
}