unity3d 清空控制台

发布时间 2023-09-21 15:47:02作者: 西北逍遥

unity3d 清空控制台

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using UnityEngine.UI;
using AssemblyCSharp;


using System;

#if UNITY_EDITOR
using UnityEditor;
#endif

public class VCClearConsole : MonoBehaviour {

    // Use this for initialization
    void Start () {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Time.frameCount % 2000 == 0)
        {
            //ClearConsole();
            ClearConsole2();
        }
    }

    #region
    /// <summary>
    /// unity3d新版本,清空控制台
    /// </summary>
    public static void ClearConsole()
    {

        System.Reflection.Assembly assembly = System.Reflection.Assembly.GetAssembly(typeof(SceneView));
        Type logEntries = assembly.GetType("UnityEditor.LogEntries");
        System.Reflection.MethodInfo clearConsoleMethod = logEntries.GetMethod("Clear");
        clearConsoleMethod.Invoke(new object(), null);
    }
    #endregion


    #region
    /// <summary>
    /// unity3d旧版本,清空控制台
    /// </summary>
    public static void ClearConsole2()
    {
        var logEntries = System.Type.GetType("UnityEditorInternal.LogEntries,UnityEditor.dll");
        var clearMethod = logEntries.GetMethod("Clear", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
        clearMethod.Invoke(null, null);
    }
    #endregion
}

 

 

 

##########################