From b8f554f03a6114db353736741eda63bdd6c63854 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期三, 22 四月 2026 10:06:52 +0800
Subject: [PATCH] 125 战斗 战斗代码整理 修复卡死问题
---
Main/System/Battle/BattleDebug.cs | 42 +++++++++++++++++++++++++++++++++++++++++-
1 files changed, 41 insertions(+), 1 deletions(-)
diff --git a/Main/System/Battle/BattleDebug.cs b/Main/System/Battle/BattleDebug.cs
index caa6a06..ac44a9a 100644
--- a/Main/System/Battle/BattleDebug.cs
+++ b/Main/System/Battle/BattleDebug.cs
@@ -3,12 +3,52 @@
public static class BattleDebug
{
+#if UNITY_EDITOR
+ // 姣忔 Editor 杩涘叆 PlayMode 浼氶噸缃繖涓� static锛屽垵娆¤皟鐢ㄦ椂娓呯┖鏃ф枃浠�
+ private static bool _logFileInitialized = false;
+ private static string _logFilePath;
+
+ private static void EnsureLogFile()
+ {
+ if (_logFileInitialized) return;
+ _logFileInitialized = true;
+ try
+ {
+ string dir = Application.dataPath + "/../BattleReport";
+ if (!System.IO.Directory.Exists(dir))
+ System.IO.Directory.CreateDirectory(dir);
+ _logFilePath = dir + "/BattleDebug.log";
+ // 姣忔鍚姩 PlayMode 娓呯┖鏂囦欢锛岄伩鍏嶈法娆℃薄鏌�
+ System.IO.File.WriteAllText(_logFilePath, $"=== BattleDebug log opened at {System.DateTime.Now:HH:mm:ss.fff} ===\n");
+ }
+ catch (System.Exception e)
+ {
+ Debug.LogWarning("BattleDebug 鎵撳紑鏃ュ織鏂囦欢澶辫触锛�" + e.Message);
+ _logFilePath = null;
+ }
+ }
+
+ private static void WriteToFile(string line)
+ {
+ EnsureLogFile();
+ if (string.IsNullOrEmpty(_logFilePath)) return;
+ try
+ {
+ System.IO.File.AppendAllText(_logFilePath,
+ $"[{Time.frameCount} {Time.realtimeSinceStartup:F3}] " + line + "\n");
+ }
+ catch { /* 蹇界暐鏂囦欢鍐欏叆寮傚父锛屽埆褰卞搷閫昏緫 */ }
+ }
+#endif
+
public static void LogError(string _logMessage)
{
#if UNITY_EDITOR
- if (Launch.Instance.isOpenBattleDebug)
+ if (Launch.Instance != null && Launch.Instance.isOpenBattleDebug)
{
Debug.LogWarning("BattleLog: " + _logMessage);
+ if (Launch.Instance.isOpenBattleDebugLogFile)
+ WriteToFile(_logMessage);
}
#endif
}
--
Gitblit v1.8.0