安卓版问题修复
This commit is contained in:
@@ -5,6 +5,7 @@ using AibisDream.Kit;
|
||||
using AibisDream.UI;
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using AibisDream.Utility;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
@@ -13,12 +14,15 @@ namespace AibisDream
|
||||
/// </summary>
|
||||
public class SettingLoader
|
||||
{
|
||||
private static readonly string SettingPath = Path.Combine(Application.streamingAssetsPath, "Config", "setting.json");
|
||||
private static readonly string SettingPath = Path.Combine(Application.persistentDataPath, "AllOurBrokenParts", "Config", "setting.json");
|
||||
private static readonly string SettingDefaultPath = Path.Combine(Application.streamingAssetsPath, "Config", "setting.json");
|
||||
|
||||
private readonly ConfigContainer _container;
|
||||
|
||||
private SettingLoader()
|
||||
{
|
||||
// 初始化设置文件(如果不存在)
|
||||
InitSettingFile();
|
||||
// 读取数据
|
||||
_container = new ConfigContainer(SettingPath);
|
||||
LoadAllSetting();
|
||||
@@ -31,6 +35,44 @@ namespace AibisDream
|
||||
_container.OnWrite -= OnSettingChanged;
|
||||
}
|
||||
|
||||
private void InitSettingFile()
|
||||
{
|
||||
// 如果文件存在,则直接返回
|
||||
if (File.Exists(SettingPath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果文件不存在,则复制默认设置并根据系统语言设置初始语言值
|
||||
var defaultSetting = JsonUtil.ReadJObject(SettingDefaultPath);
|
||||
|
||||
// 根据当前系统语言设置初始语言值
|
||||
string systemLanguage = GetLanguageBySystemLanguage();
|
||||
defaultSetting["Language"] = systemLanguage;
|
||||
|
||||
// 保存设置文件
|
||||
JsonUtil.SaveJObject(defaultSetting, SettingPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据系统语言获取对应的语言代码
|
||||
/// </summary>
|
||||
/// <returns>语言代码:zh-Hans、en、ja-JP,默认返回 en</returns>
|
||||
private string GetLanguageBySystemLanguage()
|
||||
{
|
||||
SystemLanguage systemLang = Application.systemLanguage;
|
||||
|
||||
return systemLang switch
|
||||
{
|
||||
SystemLanguage.Chinese => "zh-Hans",
|
||||
SystemLanguage.ChineseSimplified => "zh-Hans",
|
||||
SystemLanguage.ChineseTraditional => "zh-Hans",
|
||||
SystemLanguage.Japanese => "ja-JP",
|
||||
SystemLanguage.English => "en",
|
||||
_ => "en",
|
||||
};
|
||||
}
|
||||
|
||||
private void LoadAllSetting()
|
||||
{
|
||||
var settingConfig = _container.ReadAll();
|
||||
|
||||
Reference in New Issue
Block a user