68 lines
1.7 KiB
C#
68 lines
1.7 KiB
C#
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;
|
||
}
|
||
}
|
||
} |