Auto Clear Unity Console Log

功能

可以在Editor模式下执行,当然也可以Runtime模式下执行,自动清除 Console的log信息

Auto Clear Unity Console Log

功能需求

当在制作Editor的一些功能时,常常需要手动的点击Console窗口的Clear来清除日志,通过这个方法可以很方便的在脚本编译后自动清除日志

[InitializeOnLoad]
[ExecuteInEditMode]
public partial class CSimulateEnv : MonoBehaviour
{
static CSimulateEnv()
{
ClearLog();
}
}

示例代码

using System.Reflection;
using UnityEngine; public class ClearTest : MonoBehaviour
{
// Use this for initialization
void Start()
{
ClearLog();
} void OnGUI()
{
if (GUILayout.Button(" clear "))
{
ClearLog();
}
} public void ClearLog()
{
var assembly = Assembly.GetAssembly(typeof(UnityEditor.ActiveEditorTracker));
var type = assembly.GetType("UnityEditorInternal.LogEntries");
var method = type.GetMethod("Clear");
method.Invoke(new object(), null);
}
}

参考资料

http://answers.unity3d.com/questions/10580/editor-script-how-to-clear-the-console-output-wind.html

上一篇:hadoop-网站收藏


下一篇:关于TD邮件功能不能发到认证邮箱的解决之法