安卓优化
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using AibisDream.Utility;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
internal class LogKit : MonoBehaviour
|
||||
internal static class LogKit
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件名称格式
|
||||
@@ -11,11 +12,6 @@ namespace AibisDream.Kit
|
||||
/// </summary>
|
||||
public static string LogFileName => "Log{0:_yyyy_MM_dd}.txt";
|
||||
|
||||
/// <summary>
|
||||
/// 日志文件路径
|
||||
/// </summary>
|
||||
public static string LogPath => Application.streamingAssetsPath + "/LogFile";
|
||||
|
||||
/// <summary>
|
||||
/// 日志保存最近几天的内容
|
||||
/// </summary>
|
||||
@@ -26,29 +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);
|
||||
_fileLogger = new FileLogger(LogFileName, LogPath, SaveDays, Application.version);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user