From 7ea472f97e0ed23852f45dd6cf70ce9eb6010f6a Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Fri, 1 Dec 2023 10:45:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=97=A5=E5=BF=97=E9=87=8D?= =?UTF-8?q?=E5=AE=9A=E5=90=91=E4=B8=8B=E5=B1=82=E6=97=A5=E5=BF=97=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修正日志重定向下层日志跳转功能 --- .../TEngine/Editor/Utility/LogRedirection.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/UnityProject/Assets/TEngine/Editor/Utility/LogRedirection.cs b/UnityProject/Assets/TEngine/Editor/Utility/LogRedirection.cs index ced06ec3..ac27b0a6 100644 --- a/UnityProject/Assets/TEngine/Editor/Utility/LogRedirection.cs +++ b/UnityProject/Assets/TEngine/Editor/Utility/LogRedirection.cs @@ -19,6 +19,21 @@ namespace TEngine.Editor { return false; } + // 获取资源路径 + string assetPath = AssetDatabase.GetAssetPath(instanceID); + + // 判断资源类型 + if (!assetPath.EndsWith(".cs")) + { + return false; + } + + bool autoFirstMatch = assetPath.Contains("Logger.cs") || + assetPath.Contains("DefaultLogHelper.cs") || + assetPath.Contains("GameFrameworkLog.cs") || + assetPath.Contains("AssetsLogger.cs") || + assetPath.Contains("Log.cs"); + var stackTrace = GetStackTrace(); if (!string.IsNullOrEmpty(stackTrace) && (stackTrace.Contains("[Debug]") || stackTrace.Contains("[INFO]") || @@ -28,6 +43,15 @@ namespace TEngine.Editor stackTrace.Contains("[EXCEPTION]"))) { + if (!autoFirstMatch) + { + var fullPath = UnityEngine.Application.dataPath.Substring(0, UnityEngine.Application.dataPath.LastIndexOf("Assets", StringComparison.Ordinal)); + fullPath = $"{fullPath}{assetPath}"; + // 跳转到目标代码的特定行 + InternalEditorUtility.OpenFileAtLineExternal(fullPath.Replace('/', '\\'), line); + return true; + } + // 使用正则表达式匹配at的哪个脚本的哪一行 var matches = Regex.Match(stackTrace, @"\(at (.+)\)", RegexOptions.IgnoreCase);