fixes/add define

This commit is contained in:
DCFApixels 2025-03-21 19:04:50 +08:00
parent 3ae210b4bc
commit b03e212c6d
3 changed files with 62 additions and 45 deletions

View File

@ -16,6 +16,13 @@
public class EcsUnityDefines public class EcsUnityDefines
{ {
public const bool DRAGONECS_ENABLE_UNITY_CONSOLE_SHORTCUT_LINKS =
#if DRAGONECS_ENABLE_UNITY_CONSOLE_SHORTCUT_LINKS
true;
#else
false;
#endif
public const bool ENABLE_IL2CPP = public const bool ENABLE_IL2CPP =
#if ENABLE_IL2CPP #if ENABLE_IL2CPP
true; true;

View File

@ -45,9 +45,11 @@ namespace DCFApixels.DragonECS
Debug.LogException(e); Debug.LogException(e);
return; return;
} }
string msg = AutoConvertObjectToString(v);
string indexedLink = UnityDebugServiceStorage.NewIndexedLink();
bool hasTag = string.IsNullOrEmpty(tag) == false; bool hasTag = string.IsNullOrEmpty(tag) == false;
string msg = AutoConvertObjectToString(v);
#if DRAGONECS_ENABLE_UNITY_CONSOLE_SHORTCUT_LINKS
string indexedLink = UnityDebugServiceStorage.NewIndexedLink();
if (hasTag) if (hasTag)
{ {
string taglower = tag.ToLower(); string taglower = tag.ToLower();
@ -73,6 +75,33 @@ namespace DCFApixels.DragonECS
return; return;
} }
Debug.Log($"{indexedLink}{msg}"); Debug.Log($"{indexedLink}{msg}");
#else
if (hasTag)
{
string taglower = tag.ToLower();
switch (taglower)
{
case "pass":
Debug.Log(
$"[<color=#00ff00>{tag}</color>] {msg}");
break;
case "warning":
Debug.LogWarning(
$"[<color=#ffff00>{tag}</color>] {msg}");
break;
case "error":
Debug.LogError(
$"[<color=#ff4028>{tag}</color>] {msg}");
break;
default:
Debug.Log(
$"[{tag}] {msg}");
break;
}
return;
}
Debug.Log($"{msg}");
#endif
} }
public override void Break() public override void Break()
{ {

View File

@ -1,4 +1,5 @@
#if UNITY_EDITOR #if UNITY_EDITOR
#if DRAGONECS_ENABLE_UNITY_CONSOLE_SHORTCUT_LINKS
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
@ -51,7 +52,12 @@ namespace DCFApixels.DragonECS.Unity.Internal
internal const int IntervalChecksTicksThreshold = 100; internal const int IntervalChecksTicksThreshold = 100;
internal static int _consoleLogCounter; internal static int _consoleLogCounter;
internal static int _intervalChecksTicks = 0; internal static int _intervalChecksTicks = 0;
internal static StructList<LogEntry> _logEntries = new StructList<LogEntry>(256);
[SerializeField]
internal StructList<LogEntry> _logEntries = new StructList<LogEntry>(256);
[SerializeField]
private int _hyperLinkIndex = 0;
internal static object _lock = new object(); internal static object _lock = new object();
internal static void EditorGUI_hyperLinkClicked(EditorWindow window, HyperLinkClickedEventArgs args) internal static void EditorGUI_hyperLinkClicked(EditorWindow window, HyperLinkClickedEventArgs args)
@ -60,34 +66,15 @@ namespace DCFApixels.DragonECS.Unity.Internal
} }
internal static void OnProcessClickData(Dictionary<string, string> infos) internal static void OnProcessClickData(Dictionary<string, string> infos)
{ {
var inst = instance;
if (infos == null) return; if (infos == null) return;
if (!infos.TryGetValue("href", out var path)) return; if (!infos.TryGetValue("href", out var path)) return;
for (int i = 0; i < _logEntries.Count; i++) for (int i = 0; i < inst._logEntries.Count; i++)
{ {
ref var e = ref _logEntries._items[i]; ref var e = ref inst._logEntries._items[i];
if (CheckLogWithIndexedLink(e.LogString)) if (CheckLogWithIndexedLink(e.LogString))
{ {
//int indexof = e.LogString.LastIndexOf(INDEXED_LINK_PREV) - 1 + INDEXED_LINK_PREV.Length;// откатываю символ ∆
//int stringIndexLength = e.LogString.Length - (indexof + INDEXED_LINK_POST.Length);
//
//if(stringIndexLength == path.Length)
//{
// bool isSkip = false;
// for (int j = 1; j < stringIndexLength; j++)
// {
// var pathchar = path[j];
// var logchar = e.LogString[indexof + j];
// if (pathchar != logchar) { isSkip = true; break; }
// }
//
// if (isSkip) { continue; }
//
// OpenIDE(e);
//
// break;
//}
int indexof = INDEXED_LINK_PREV.Length - 1;// откатываю символ ∆ int indexof = INDEXED_LINK_PREV.Length - 1;// откатываю символ ∆
int stringIndexLength = e.LogString.IndexOf(INDEXED_LINK_POST) - indexof; int stringIndexLength = e.LogString.IndexOf(INDEXED_LINK_POST) - indexof;
@ -139,12 +126,13 @@ namespace DCFApixels.DragonECS.Unity.Internal
internal static void Application_logMessageReceived(string logString, string stackTrace, LogType type) internal static void Application_logMessageReceived(string logString, string stackTrace, LogType type)
{ {
var inst = instance;
if (_intervalChecksTicks >= IntervalChecksTicksThreshold || if (_intervalChecksTicks >= IntervalChecksTicksThreshold ||
_logEntries.Count >= _logEntries.Capacity - 1) inst._logEntries.Count >= inst._logEntries.Capacity - 1)
{ {
CheckConsoleClean(); CheckConsoleClean();
} }
_logEntries.Add(new LogEntry(logString, stackTrace)); inst._logEntries.Add(new LogEntry(logString, stackTrace));
_consoleLogCounter++; _consoleLogCounter++;
_intervalChecksTicks++; _intervalChecksTicks++;
@ -155,14 +143,15 @@ namespace DCFApixels.DragonECS.Unity.Internal
{ {
lock (_lock) lock (_lock)
{ {
var inst = instance;
if (_intervalChecksTicks < IntervalChecksTicksThreshold) { return false; } if (_intervalChecksTicks < IntervalChecksTicksThreshold) { return false; }
int currentCount = GetConsoleLogCount(); int currentCount = GetConsoleLogCount();
if (_consoleLogCounter > currentCount) if (_consoleLogCounter > currentCount)
{ {
var l = _consoleLogCounter - currentCount; var l = _consoleLogCounter - currentCount;
if(l < _logEntries.Count) if(l < inst._logEntries.Count)
{ {
_logEntries.FastRemoveSpan(0, l); inst._logEntries.FastRemoveSpan(0, l);
} }
_consoleLogCounter = currentCount; _consoleLogCounter = currentCount;
@ -174,7 +163,7 @@ namespace DCFApixels.DragonECS.Unity.Internal
} }
private const string INDEXED_LINK_PREV = "<a href=\"∆"; private const string INDEXED_LINK_PREV = "<a href=\"∆";
private const string INDEXED_LINK_POST = "\"> </a>"; private const string INDEXED_LINK_POST = "\"> </a>";
private static string CreateIndexedLink(int index) private static string CreateIndexedLink(int index)
{ {
return $"{INDEXED_LINK_PREV}{index}{INDEXED_LINK_POST}"; return $"{INDEXED_LINK_PREV}{index}{INDEXED_LINK_POST}";
@ -187,7 +176,6 @@ namespace DCFApixels.DragonECS.Unity.Internal
{ {
return instance.GetHyperLink_Internal(); return instance.GetHyperLink_Internal();
} }
private static int _hyperLinkIndex = 0;
public string GetHyperLink_Internal() public string GetHyperLink_Internal()
{ {
var index = Interlocked.Increment(ref _hyperLinkIndex); var index = Interlocked.Increment(ref _hyperLinkIndex);
@ -197,16 +185,7 @@ namespace DCFApixels.DragonECS.Unity.Internal
private static bool CheckLogWithIndexedLink(string log) private static bool CheckLogWithIndexedLink(string log)
{ {
//if (log.Length < INDEXED_LINK_POST.Length) { return false; } if (log == null) { return false; }
//for (int i = 0; i < INDEXED_LINK_POST.Length; i++)
//{
// char constChar = INDEXED_LINK_POST[i];
// char logChar = log[log.Length - INDEXED_LINK_POST.Length + i];
// if (constChar != logChar) { return false; }
//}
//return true;
if (log.Length < INDEXED_LINK_PREV.Length) { return false; } if (log.Length < INDEXED_LINK_PREV.Length) { return false; }
for (int i = 0; i < INDEXED_LINK_PREV.Length; i++) for (int i = 0; i < INDEXED_LINK_PREV.Length; i++)
{ {
@ -217,10 +196,11 @@ namespace DCFApixels.DragonECS.Unity.Internal
return true; return true;
} }
internal readonly struct LogEntry [Serializable]
internal struct LogEntry
{ {
public readonly string LogString; public string LogString;
public readonly string StackTrace; public string StackTrace;
public LogEntry(string logString, string stackTrace) public LogEntry(string logString, string stackTrace)
{ {
LogString = logString; LogString = logString;
@ -230,3 +210,4 @@ namespace DCFApixels.DragonECS.Unity.Internal
} }
} }
#endif #endif
#endif