private static void ClearConsole()
{
#if UNITY_EDITOR
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetAssembly(typeof(UnityEditor.SceneView));
System.Type logEntries = assembly.GetType("UnityEditor.LogEntries");
System.Reflection.MethodInfo clearConsoleMethod = logEntries.GetMethod("Clear");
clearConsoleMethod.Invoke(new object(), null);
#endif
}
忘记以前在哪里找到的,原理似乎是模拟点击了一下Console窗口上的Clear按钮,很好用反正。
文章描述了一个在Unity编辑器环境下,使用reflection和类型获取技术调用LogEntries类的Clear方法来清空Console的方法,类似于模拟点击Clear按钮的行为。
5301






