功能

可以在Editor模式下执行,当然也可以Runtime模式下执行,自动清除 Console的log信息

功能需求

当在制作Editor的一些功能时,常常需要手动的点击Console窗口的Clear来清除日志,通过这个方法可以很方便的在脚本编译后自动清除日志

[InitializeOnLoad]
[ExecuteInEditMode]
public partial class CSimulateEnv : MonoBehaviour
{
static CSimulateEnv()
{
ClearLog();
}
}

示例代码

using System.Reflection;
using UnityEngine; public class ClearTest : MonoBehaviour
{
// Use this for initialization
void Start()
{
ClearLog();
} void OnGUI()
{
if (GUILayout.Button(" clear "))
{
ClearLog();
}
} public void ClearLog()
{
var assembly = Assembly.GetAssembly(typeof(UnityEditor.ActiveEditorTracker));
var type = assembly.GetType("UnityEditorInternal.LogEntries");
var method = type.GetMethod("Clear");
method.Invoke(new object(), null);
}
}

参考资料

http://answers.unity3d.com/questions/10580/editor-script-how-to-clear-the-console-output-wind.html

最新文章

  1. PHP-----文件系统的交互
  2. js 基础面试题
  3. 第二章 jQuery数组和字符串
  4. 分享一些App常用的模块
  5. WEB-INF& 绝对路径vs相对路径
  6. hdu 2055
  7. python之类定义
  8. TI的AM3359的sd卡分区以及sd卡启动说明
  9. 关于atoi的实现
  10. java新手笔记6 示例for
  11. ​C语言数组作为函数参数
  12. windows下qtcreator添加ICE库文件
  13. ios开发之路十一(ARC forbids explicit message send of 'autorelease'错误)
  14. Ubuntu 忘记密码
  15. Codeforces Round #436 (Div. 2) E. Fire
  16. K:java中的hashCode和equals方法
  17. oracel 拆分字符串
  18. ArcGIS案例教程-通过点坐标生成矩形
  19. zigbee_蓝牙_wifi的比较与区别分析
  20. 1. github配置

热门文章

  1. 自定义XML动态配置程序
  2. IE浏览器中ajax使用缓存数据的问题
  3. 转载 BCS 的好文章 1 - 怎么创建和使用BCS
  4. vsphere vcenter server下安装ubuntu的vmwaretools
  5. 《C程序设计的抽象思维》1.9编程练习
  6. storyBoard配置错误导致崩溃 superview]: unrecognized selector...
  7. 大家一起和snailren学java-(二)一切都是对象
  8. 换新 iPhone 前要做的 9 件事
  9. Effective Java 21 Use function objects to represent strategies
  10. cxf数据压缩