generated from techno-dwarf-works/unity-package-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
189 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,24 @@ | ||
using System.Collections.Generic; | ||
using Better.EditorTools.SettingsTools; | ||
using Better.Internal.Core.Runtime; | ||
using Better.Logger.Runtime.Settings; | ||
using Better.Tools.Runtime; | ||
using Better.ProjectSettings.EditorAddons; | ||
using UnityEditor; | ||
|
||
namespace Better.Logger.EditorAddons.Settings | ||
{ | ||
internal class ValidationSettingProvider : ProjectSettingsProvider<LoggerSettings> | ||
internal class LoggerSettingProvider : DefaultProjectSettingsProvider<LoggerSettings> | ||
{ | ||
private readonly Editor _editor; | ||
|
||
public ValidationSettingProvider() : base(ProjectSettingsToolsContainer<LoggerSettingsTool>.Instance, SettingsScope.Project) | ||
private const string Path = PrefixConstants.BetterPrefix + "/" + nameof(Logger); | ||
public LoggerSettingProvider() : base(Path) | ||
{ | ||
keywords = new HashSet<string>(new[] { "Better", "Logger", "Warnings", "Debug", "Error", "Exception", "Ignore", "Log" }); | ||
_editor = Editor.CreateEditor(_settings); | ||
} | ||
|
||
[MenuItem(LoggerSettingsTool.MenuItemPrefix + "/" + BetterEditorDefines.HighlightPrefix, false, 999)] | ||
[MenuItem(Path + "/" + PrefixConstants.HighlightPrefix, false, 999)] | ||
private static void Highlight() | ||
{ | ||
SettingsService.OpenProjectSettings(ProjectSettingsToolsContainer<LoggerSettingsTool>.Instance.ProjectSettingKey); | ||
} | ||
|
||
protected override void DrawGUI() | ||
{ | ||
_editor.OnInspectorGUI(); | ||
SettingsService.OpenProjectSettings(ProjectPath + Path); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System; | ||
using System.Reflection; | ||
using System.Text.RegularExpressions; | ||
using Better.Extensions.Runtime; | ||
|
||
namespace Better.Logger.Runtime | ||
{ | ||
public static class LoggerUtility | ||
{ | ||
private static readonly string _firstCallerPattern = $@"(?<{ClassNameTag}>\w+)\.(?<{MethodNameTag}>\w+)\s*\(\s*\)"; | ||
private static readonly string _lambdaNamePattern = @"<(.*?)>"; | ||
private const string MethodNameFormat = "{0}{1}"; | ||
private const string ClassNameTag = "ClassName"; | ||
private const string MethodNameTag = "MethodName"; | ||
private const string Unknown = "Unknown"; | ||
|
||
public static string GetDeclaringTypeName(MethodBase methodBase) | ||
{ | ||
if (methodBase == null) | ||
{ | ||
return Unknown; | ||
} | ||
|
||
var declaringType = methodBase.DeclaringType; | ||
if (declaringType == null) return "Global"; | ||
if (declaringType.IsAnonymous()) | ||
{ | ||
declaringType = declaringType.ReflectedType; | ||
} | ||
|
||
return declaringType != null ? declaringType.Name : "Global"; | ||
} | ||
|
||
|
||
|
||
public static bool TryGetFirstCaller(Exception exception, out (string ClassName, string MethodName) info) | ||
{ | ||
if (string.IsNullOrEmpty(exception.StackTrace)) | ||
{ | ||
info = new(Unknown, Unknown); | ||
return false; | ||
} | ||
|
||
// Use Regex to find matches in the input string | ||
var match = Regex.Match(exception.StackTrace, _firstCallerPattern); | ||
|
||
var classNameGroup = match.Groups[ClassNameTag]; | ||
var methodNameGroup = match.Groups[MethodNameTag]; | ||
if (!classNameGroup.Success || !methodNameGroup.Success) | ||
{ | ||
info = new(Unknown, Unknown); | ||
return false; | ||
} | ||
|
||
var className = classNameGroup.Value; | ||
var methodName = methodNameGroup.Value; | ||
info = new(className, methodName); | ||
return true; | ||
} | ||
|
||
public static string GetMethodName(MethodBase methodBase) | ||
{ | ||
if (methodBase == null) | ||
{ | ||
return Unknown; | ||
} | ||
|
||
var name = ExtractMethodName(methodBase.Name); | ||
|
||
switch (name) | ||
{ | ||
case ".ctor": | ||
case ".cctor": | ||
var typeName = GetDeclaringTypeName(methodBase); | ||
return string.Format(MethodNameFormat, typeName, name); | ||
} | ||
|
||
return name; | ||
} | ||
|
||
|
||
public static string ExtractMethodName(string methodName) | ||
{ | ||
// Simplified regex pattern to match only within < and > | ||
var match = Regex.Match(methodName, _lambdaNamePattern); | ||
|
||
if (match.Success) | ||
{ | ||
// Group 1 contains the method name | ||
return match.Groups[1].Value; | ||
} | ||
|
||
return methodName; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.