Unity在编辑器下清空控制台中的Debug.Log()信息

393 阅读1分钟

清空控制台中的信息

    private void Update()
    {
#if UNITY_EDITOR
        if (Input.GetKeyDown(KeyCode.D) && Input.GetKey(KeyCode.C))
        {
            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 
    }

在运行的时候按下C+D可以清空控制台中的信息,
在发布的时候这段代码并不会被执行。

完整的脚本

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


public class ClearConsole_Mine : MonoBehaviour
{
    private bool m_ClearConsole = false;
    private void Update()
    {
#if UNITY_EDITOR
        if (Input.GetKeyDown(KeyCode.D) && Input.GetKey(KeyCode.C))
        {
            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 
    }
}