We are using a custom DebugUtils class which provides some nice tweaks such as filtering messages by person or type.
The problem is that when you double click the console window, it makes Mono load up the DebugUtils class/function and not the original calling script.
Can anyone suggest a solution or direction to look into that will make double clicking one of these messages go to the orignal script?
Cheers!
I had the same problem, then I just made a simple DLL (with Mono) with this unique static class :
using System;
using UnityEngine;
namespace [MyNameSpace]
{
public static class MyDebug
{
public static string TAG = "MyUnity";
public static string CurrentClass
{
get {
var st = new System.Diagnostics.StackTrace();
var index = Mathf.Min(st.FrameCount - 1, 2);
if (index < 0)
return "{NoClass}";
return "{" + st.GetFrame(index).GetMethod().DeclaringType.Name + "}";
}
}
public static void Log(string Msg)
{
if (Debug.isDebugBuild)
Debug.Log(string.Format("{0}:{1}:{2}", TAG, CurrentClass, Msg));
}
public static void LogWarning(string Msg)
{
Debug.LogWarning(string.Format("{0}:{1}:{2}", TAG, CurrentClass, Msg));
}
public static void LogError(string Msg)
{
Debug.LogError(string.Format("{0}:{1}:{2}", TAG, CurrentClass, Msg));
}
}
}
Then, back in Unity you just have to past your plugin.dll in your asset folder and in the code side:
using [MyNameSpace];
// In method
MyDebug.Log("My message log");
In the console you will see:
“MyUnity:{ClassName}:My message log”
And if you dbl click on it you will open the ClassName file at the right line!
It works like a charm!
I’ve been working on something like this. I can open the external editor at the correct spot, but I am searching for something that will let me set the console double click goto position.
Here is my code for that which gets called by my internal debugging system. If you found out how let me know or if any one else has any tips.
private static void OpenFile()
{
Assembly assembly = Assembly.GetAssembly(typeof(UnityEditor.SceneView));
System.Type type = assembly.GetType("UnityEditorInternal.InternalEditorUtility");
if(type == null)
{
Debug.Log("Failed to open source file");
return;
}
string[] stackFrames = System.Environment.StackTrace.Split(new char[] {'
’ });
string callingFrame = stackFrames[4];
string[] splitLog = callingFrame.Split(':');
char drive = splitLog[0][splitLog[0].Length-1];
string filePath = splitLog[1];
splitLog[2] = StringManipulation.TrimStartString(
splitLog[2], "line ");
int lineNumber = int.Parse(StringManipulation.GetBeforeNextChar(
splitLog[2], '
'));
string fullDrive = drive + ":" + filePath;
//Debug.Log(@fullDrive + " line #" + lineNumber );
MethodInfo method = type.GetMethod("OpenFileAtLineExternal");
method.Invoke(method, new object[] { @fullDrive, lineNumber });
}
(Here is that “StringManipulation” method I use which I am sure you could have figured out if you are reading this question.
public static string GetBeforeNextChar(string sourceString, char trimed)
{
string[] splits = sourceString.Split(trimed);
return splits[0];
}
public static string TrimStartCharacter(string sourceString, char trimed)
{
sourceString = sourceString.TrimStart(trimed);
return sourceString;
}
Our editor console replacement asset has this feature, see the second feature discussed in this video:
Console Enhanced
It has to be a DLL yes or yes?
I’m trying this in 2018.3.11 and it opens the MyDebug class
Here’s an example command to create a DLL using csc
that works for this problem:
csc /target:library /reference:"C:\Program Files\Unity\Hub\Editor\2022.2.0b2\Editor\Data\Managed\UnityEngine.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\Facades
etstandard.dll" …/Assets/Scripts/Utils/DebugBW.cs
/target:library
gets you a dll
/reference: .../UnityEngine.dll
for your Unity imports. If you have other using
s you may need to reference them here.
/reference: .../netstandard.dll
standard .NET lib. Mine wouldn’t work without this but yours might.