反射调用untiy编辑器清空debug控制台

using UnityEngine;
using UnityEditor;
using System.Reflection;

public class Script_Clear
{
    [MenuItem("Tools/CreateConsole")]
    static void CreateConsole()
    {
        Debug.Log("CreateConsole");
    }

    [MenuItem("Tools/CleanConsole")]
    static void CleanConsole()
    {
        //获取assembly
        Assembly assembly = Assembly.GetAssembly(typeof(Editor));
        //反射获取LogEntries对象
        MethodInfo methodInfo = assembly.GetType("UnityEditor.LogEntries").
            GetMethod("Clear");
        //反射调用它的Clear方法
        methodInfo.Invoke(new object(), null);
    }
}

 

posted @ 2022-07-12 17:40  枫亦  阅读(12)  评论(0)    收藏  举报