Skip to content

Instantly share code, notes, and snippets.

@VasylRomanets
Forked from talecrafter/ConsoleUtilitiesEditor.cs
Last active August 30, 2017 13:38
Show Gist options
  • Select an option

  • Save VasylRomanets/2d16950d88842cde4e141caf62c436a5 to your computer and use it in GitHub Desktop.

Select an option

Save VasylRomanets/2d16950d88842cde4e141caf62c436a5 to your computer and use it in GitHub Desktop.
using System;
using System.Reflection;
using UnityEditor;
public static class ConsoleUtilitiesEditor
{
[MenuItem("Tools/Clear Console %#c")] // Cmd/Ctrl + Shift + C
private static void ClearConsoleMenuItem()
{
ClearConsole();
}
public static void ClearConsole()
{
Assembly assembly = Assembly.GetAssembly(typeof(SceneView));
if (assembly != null)
{
Type logEntriesType;
#if UNITY_2017_1_OR_NEWER
logEntriesType = assembly.GetType("UnityEditor.LogEntries");
#else
logEntriesType = assembly.GetType("UnityEditorInternal.LogEntries");
#endif
if (logEntriesType != null)
{
var clearMethod = logEntriesType.GetMethod("Clear", BindingFlags.Static | BindingFlags.Public);
clearMethod.Invoke(null, null);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment