Created
August 25, 2017 09:35
-
-
Save talecrafter/d6eab8c2537d94559093c7c0cb190e31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using System.Reflection; | |
using System; | |
public static class ConsoleUtilitiesEditor | |
{ | |
[MenuItem("Tools/Clear Console %#c")] // Cmd/Ctrl + Shift + C | |
private static void ClearConsoleMenuItem() | |
{ | |
ClearConsole(); | |
} | |
public static void ClearConsole() | |
{ | |
#if UNITY_2017_1_OR_NEWER | |
Assembly assembly = Assembly.GetAssembly(typeof(SceneView)); | |
if (assembly != null) | |
{ | |
Type logEntriesType = assembly.GetType("UnityEditor.LogEntries"); | |
if (logEntriesType != null) | |
{ | |
var clearMethod = logEntriesType.GetMethod("Clear", BindingFlags.Static | BindingFlags.Public); | |
clearMethod.Invoke(null, null); | |
} | |
} | |
#else | |
Assembly assembly = Assembly.GetAssembly(typeof(SceneView)); | |
if (assembly != null) | |
{ | |
Type logEntriesType = assembly.GetType("UnityEditorInternal.LogEntries"); | |
if (logEntriesType != null) | |
{ | |
var clearMethod = logEntriesType.GetMethod("Clear", BindingFlags.Static | BindingFlags.Public); | |
clearMethod.Invoke(null, null); | |
} | |
} | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment