安卓优化
This commit is contained in:
@@ -4,6 +4,8 @@ using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using AibisDream.UI;
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using AibisDream.Utility;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
@@ -12,12 +14,15 @@ namespace AibisDream
|
||||
/// </summary>
|
||||
public class SettingLoader
|
||||
{
|
||||
private static readonly string SettingPath = 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();
|
||||
@@ -30,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();
|
||||
@@ -55,7 +98,9 @@ namespace AibisDream
|
||||
break;
|
||||
case "WindowMode":
|
||||
// 屏幕模式
|
||||
#if !UNITY_ANDROID && !UNITY_IOS
|
||||
GameManager.Instance.SetScreenMode(value);
|
||||
#endif
|
||||
break;
|
||||
case "Language":
|
||||
// 确保本地化系统已初始化
|
||||
|
||||
Reference in New Issue
Block a user