using BepInEx;
using BepInEx.Configuration;
using UnityEngine;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using System.Diagnostics;
using Debug = UnityEngine.Debug;
using System.Reflection;
namespace YourNamespace
{
[BepInPlugin("com.example.myplugin", "My Plugin", "1.0.0")]
public class MyPlugin : BaseUnityPlugin
{
private ConfigEntry<int> myConfig;
private Dictionary<string, string> localizationData;
private void Awake()
{
// 加载和解析本地化文件
string localizationFilePath = Path.Combine(Paths.PluginPath, "Localization", "en.json");
string localizationDataJson = File.ReadAllText(localizationFilePath);
localizationData = JsonConvert.DeserializeObject<Dictionary<string, string>>(localizationDataJson);
// 创建配置项,使用本地化的描述文本
myConfig = Config.Bind<int>("General", "MyConfig", 0, GetLocalizedDescription("MyConfigDescription"));
}
private string GetLocalizedDescription(string key)
{
if (localizationData.ContainsKey(key))
{
return localizationData[key];
}
else
{
Debug.LogError($"Localization key not found: {key}");
return string.Empty;
}
}
}
}
本地化文件json写法
{
"MyConfigDescription": "测试"
}
没有回复内容