安卓版问题修复

This commit is contained in:
2025-12-19 18:36:22 +08:00
parent 17999eb4ca
commit afa2e251df
14 changed files with 771 additions and 58 deletions
+18 -8
View File
@@ -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;
}
}
}