反射调用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); } }

浙公网安备 33010602011771号