我想为 Unity3d 项目编写一个中央记录器类。如果我只打印控制台日志,那将非常简单。我希望它看起来像下面这样:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//Consider this class is a Singleton, and is available to all other classes.
//I'm leaving the generic inheritance from something like Singleton<Logger> for simplicity
public class Logger : MonoBehaviour
{
public enum LogLevel
{
Verbose,
Debug,
Warn,
Error
}
public bool _enableLogs;
public LogLevel _logLevel;
public void Log(LogLevel logType, string msg)
{
if (!_enableLogs)
return;
// some logic to filter out messages below this "_logLevel".
// Log the msg to console.
Debug.Log (msg);
}
}
通常当您双击一条日志消息时,它会将您带到 MonoDevelop 文件中的那行代码。我如何修改我的代码,使其与生成它的代码行链接,就像在普通记录器中一样?非常感谢任何帮助。
最佳答案
有一个简单的解决方案可以满足您的需求:将您的记录器编译成 .DLL 并将该 .DLL 包含在您的项目中。现在,单击日志消息应该会将您带到所需的位置。
我不确定为什么会这样,但长期以来人们都知道它是这样工作的(我们也有一个像那样工作的自定义记录器)。
关于c# - Unity3d 的记录器,与 MonoDevelop 很好地连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44376919/