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);