安卓版问题修复
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using AibisDream.Utility;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
internal class LogKit : MonoBehaviour
|
||||
internal static class LogKit
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件名称格式
|
||||
@@ -23,30 +22,41 @@ namespace AibisDream.Kit
|
||||
/// </summary>
|
||||
private static string LogContent => Time + ": {0}\n{1}";
|
||||
|
||||
private FileLogger _fileLogger;
|
||||
private static FileLogger _fileLogger;
|
||||
private static bool _isInitialized;
|
||||
|
||||
private static string Time => DateTime.Now.ToString("[HH:mm:ss.fffd]");
|
||||
|
||||
private void Awake()
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
||||
private static void Initialize()
|
||||
{
|
||||
#if !UNITY_EDITOR
|
||||
DontDestroyOnLoad(gameObject);
|
||||
if (_isInitialized)
|
||||
return;
|
||||
|
||||
_fileLogger = new FileLogger(LogFileName, ConstRef.LogFilePath, SaveDays);
|
||||
LogMessage($"Ver.{Application.version}", "", LogType.Log);
|
||||
Application.logMessageReceivedThreaded += LogMessage;
|
||||
Application.quitting += Shutdown;
|
||||
_isInitialized = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
private void LogMessage(string condition, string stackTrace, LogType type)
|
||||
private static void LogMessage(string condition, string stackTrace, LogType type)
|
||||
{
|
||||
_fileLogger?.Write(string.Format(LogContent, condition, stackTrace));
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
private static void Shutdown()
|
||||
{
|
||||
if (!_isInitialized)
|
||||
return;
|
||||
|
||||
Application.logMessageReceivedThreaded -= LogMessage;
|
||||
Application.quitting -= Shutdown;
|
||||
_fileLogger?.OnDestroy();
|
||||
_fileLogger = null;
|
||||
Application.logMessageReceivedThreaded -= LogMessage;
|
||||
_isInitialized = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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