Kok*_*zzu 5 c# unity-game-engine
我有这种代码,目的是包装,UnityEngine.Debug.Log这样我就可以在生产中禁用它们,以便我可以稍后查找/过滤。
using System;
public enum LogType
{
DEBUG,
CRITICAL
}
public class LogHelper
{
public static void Log(LogType lt, string format, params object[] objs)
{
if (lt == LogType.CRITICAL)
{
// StackTrace st = new StackTrace(new StackFrame(true));
// Console.WriteLine(" Stack trace for current level: {0}", st.ToString());
// StackFrame sf = st.GetFrame(0);
// Console.WriteLine(" File: {0}", sf.GetFileName());
// Console.WriteLine(" Method: {0}", sf.GetMethod().Name);
// Console.WriteLine(" Line Number: {0}", sf.GetFileLineNumber());
// Console.WriteLine(" Column Number: {0}", sf.GetFileColumnNumber());
}
// TODO: write to /tmp file too
UnityEngine.Debug.Log("[" + lt + "] " + String.Format(format, objs));
}
public static void Critical(string format, params object[] objs)
{
Log(LogType.CRITICAL,format, objs);
}
public static void Debug(string format, params object[] objs)
{
Log(LogType.DEBUG,format, objs);
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我调用这些代码时LogHelper.Debug("something"),双击Unity编辑器的日志将转到该代码(调用的代码UnityEngine.Debug.Log)而不是调用该代码的源代码LogHelper.Debug。如何让它显示调用者而不是LogHelper双击日志时显示?
小智 2
我不确定,但尝试一下:
public static class MyDebug{
public static delegate void TestDelegate(object message);
#if (NOEDITOR)
public static TestDelegate Log =(x)=>{};
#else
public static TestDelegate Log = Debug.Log;
#endif
}
Run Code Online (Sandbox Code Playgroud)
然后,控制这个定义 NOEDITOR