mirror of
http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite.git
synced 2025-11-20 04:37:11 +08:00
(client) feat:健康给予,路径优化,结算界面,商店界面 (#60)
Co-authored-by: m0_75251201 <m0_75251201@noreply.gitcode.com> Reviewed-on: http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite/pulls/60
This commit is contained in:
@@ -7,29 +7,10 @@ namespace Logging
|
||||
{
|
||||
public static class LogCapturer
|
||||
{
|
||||
// 日志条目结构
|
||||
public struct LogEntry
|
||||
{
|
||||
public DateTime Timestamp;
|
||||
public LogType Type;
|
||||
public string Message;
|
||||
public string StackTrace;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
// 逻辑修改:扩展条件,使LogType.Error和LogType.Assert也能显示堆栈信息
|
||||
if (Type == LogType.Exception || Type == LogType.Error || Type == LogType.Assert)
|
||||
{
|
||||
return $"[{Timestamp:HH:mm:ss}] [{Type}] {Message}\n{StackTrace}";
|
||||
}
|
||||
return $"[{Timestamp:HH:mm:ss}] [{Type}] {Message}";
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Queue<LogEntry> _logs = new Queue<LogEntry>();
|
||||
private static readonly object _lock = new object(); // 线程锁
|
||||
private static readonly Queue<LogEntry> _logs = new();
|
||||
private static readonly object _lock = new(); // 线程锁
|
||||
private static int _maxLogs = 1000; // 默认容量
|
||||
private static bool _isInitialized = false; // 逻辑修改:添加一个私有标志来跟踪是否已初始化
|
||||
private static bool _isInitialized; // 逻辑修改:添加一个私有标志来跟踪是否已初始化
|
||||
|
||||
// 最大日志容量属性
|
||||
public static int MaxLogs
|
||||
@@ -57,12 +38,12 @@ namespace Logging
|
||||
Debug.LogWarning("[LogCapturer] Init() called multiple times. LogCapturer is already initialized.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Application.logMessageReceivedThreaded += HandleLog;
|
||||
_isInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 逻辑修改:添加一个 Shutdown 方法来解除事件注册和清理
|
||||
public static void Shutdown()
|
||||
{
|
||||
@@ -96,20 +77,14 @@ namespace Logging
|
||||
|
||||
_logs.Enqueue(entry);
|
||||
TrimExcess();
|
||||
if (type is LogType.Error or LogType.Assert or LogType.Exception)
|
||||
{
|
||||
UIInputControl.Instance.Show("LogUI");
|
||||
}
|
||||
if (type is LogType.Error or LogType.Assert or LogType.Exception) UIInputControl.Instance.Show("LogUI");
|
||||
}
|
||||
}
|
||||
|
||||
// 日志队列修剪
|
||||
private static void TrimExcess()
|
||||
{
|
||||
while (_logs.Count > _maxLogs)
|
||||
{
|
||||
_logs.Dequeue();
|
||||
}
|
||||
while (_logs.Count > _maxLogs) _logs.Dequeue();
|
||||
}
|
||||
|
||||
// 获取当前所有日志(倒序:最新在前)
|
||||
@@ -131,5 +106,22 @@ namespace Logging
|
||||
_logs.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
// 日志条目结构
|
||||
public struct LogEntry
|
||||
{
|
||||
public DateTime Timestamp;
|
||||
public LogType Type;
|
||||
public string Message;
|
||||
public string StackTrace;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
// 逻辑修改:扩展条件,使LogType.Error和LogType.Assert也能显示堆栈信息
|
||||
if (Type == LogType.Exception || Type == LogType.Error || Type == LogType.Assert)
|
||||
return $"[{Timestamp:HH:mm:ss}] [{Type}] {Message}\n{StackTrace}";
|
||||
return $"[{Timestamp:HH:mm:ss}] [{Type}] {Message}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user