Unity Log重新定向
Unity Log重新定向
使用Unity的Log的时候有时候需要封装一下Debug.Log(message),可以屏蔽Log或者把log内容写到文本中。通过把文本内容传送到服务器中,查找bug出现的原因。但是封装之后的日志系统如果双击跳转的时候,会跳转到自定义的日志系统脚本里面去,有些不太方便。
1、通过反射修改找到日志打印的具体位置
- 通过反射知道点击的日志的文本内容
- 通过正则表达式去匹配找到打印日志的脚本和具体的行号,如果是封装的脚本的话,继续匹配,直到结束。
public static class LogRedirect
{
private static readonly Regex LogRegex = new Regex(@" \(at (.+)\:(\d+)\)\r?\n"); /// <summary>
/// 用于在Unity中打开资产的回调属性(例如,在项目浏览器中双击资源时会触发回调)。
///将此属性添加到静态方法将使Unity在打开资产时调用该方法。该方法应具有以下签名:
///static bool OnOpenAsset(int instanceID, int line)
/// 如果处理资产的开放则返回true;如果外部工具应打开它,则返回false。
/// </summary>
/// <param name="instanceId"></param>
/// <param name="line"></param>
/// <returns></returns>
[OnOpenAssetAttribute(0)]
private static bool OnOpenAsset(int instanceId, int line)
{
string name = EditorUtility.InstanceIDToObject(instanceId).name; string msg = GetSelectedStackTrace();
Tools.FileHelper.CreateFile(Path.Combine(Application.dataPath, "ADebug/LogFile"), msg);
if (string.IsNullOrEmpty(msg)) return false;
if (!msg.Contains("Debugger.cs")) return false;
Match match = LogRegex.Match(msg);
if (!match.Success) return false; match = match.NextMatch();
if (!match.Success) return false; InternalEditorUtility.OpenFileAtLineExternal(
Path.Combine(Application.dataPath, match.Groups[1].Value.Substring(7)), int.Parse(match.Groups[2].Value));
return true;
} /// <summary>
/// 获取点击Log的文本信息
/// </summary>
/// <returns></returns>
private static string GetSelectedStackTrace()
{
Assembly editorWindowAssembly = typeof(EditorWindow).Assembly;
if (editorWindowAssembly == null)
{
return null;
} System.Type consoleWindowType = editorWindowAssembly.GetType("UnityEditor.ConsoleWindow");
if (consoleWindowType == null)
{
return null;
} FieldInfo consoleWindowFieldInfo =
consoleWindowType.GetField("ms_ConsoleWindow", BindingFlags.Static | BindingFlags.NonPublic);
if (consoleWindowFieldInfo == null)
{
return null;
} EditorWindow consoleWindow = consoleWindowFieldInfo.GetValue(null) as EditorWindow;
if (consoleWindow == null)
{
return null;
} if (consoleWindow != EditorWindow.focusedWindow)
{
return null;
} FieldInfo activeTextFieldInfo =
consoleWindowType.GetField("m_ActiveText", BindingFlags.Instance | BindingFlags.NonPublic);
if (activeTextFieldInfo == null)
{
return null;
} return (string) activeTextFieldInfo.GetValue(consoleWindow);
}
}
2、把自定义的日志脚本打包成dll文件导入。
Unity Log重新定向的更多相关文章
- Unity Log Path
{ //不是开场动画的LOG,是APK的 C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Apk\res\mipmap ...
- 定向转发和重定向实现 <select >下拉表单数据传送
定向转发的特点: (1). 实行转发时浏览器上的网址不变 (如果你这点忽视了,那你就要接受我无尽的鄙视吧! 哇咔咔~~~) (2). 实行转发时 : 只有一次请求. 不信,看这下面的 ...
- 【Redis】简介与安装
Linux 安装 [root@redis ~]# wget http://download.redis.io/releases/redis-2.8.19.tar.gz 解压缩redis[root@ha ...
- Centos6 安装 Redis
先确认gcc和tcl已经安装 sudo yum install gcc-c++ sudo yum install tcl 解压, 编译和安装 .tar.gz /usr/src/ cd /usr/src ...
- [转载] Redis 起步
转载地址:http://www.cnblogs.com/shanyou/archive/2012/01/28/2330451.html Rdis和JQuery一样是纯粹为应用而产生的,这里记录的是在C ...
- Redis 起步
Rdis和JQuery一样是纯粹为应用而产生的,这里记录的是在CentOS 5.7上学习入门文章: 1.Redis简介 Redis是一个key-value存储系统.和Memcached类似,但是解决 ...
- windows下和linux下 Redis 安装
Redis 是一个高性能的key-value数据库, 使用内存作为主存储,数据访问速度非常快,当然它也提供了两种机制支持数据持久化存储.比较遗憾的是,Redis项目不直接支持Windows,Windo ...
- Redis起步
Rdis和JQuery一样是纯粹为应用而产生的,这里记录的是在CentOS 5.7上学习入门文章: 1.Redis简介 Redis是一个key-value存储系统.和Memcached类似,但是解决 ...
- 如何在.Net中使用Redis
Redis是一个key-value存储系统.和Memcached类似,但是解决了断电后数据完全丢失的情况,而且她支持更多无化的value类型,除了和string外,还支持lists(链表).sets( ...
随机推荐
- 【Lintcode】112.Remove Duplicates from Sorted List
题目: Given a sorted linked list, delete all duplicates such that each element appear only once. Examp ...
- bzoj 3232 圈地游戏——0/1分数规划(或网络流)
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3232 当然是0/1分数规划.但加的东西和减的东西不在一起,怎么办? 考虑把它们合在一起.因为 ...
- poj3177重修道路——边双连通分量缩点
题目:http://poj.org/problem?id=3177 找桥,缩点,总之都是板子: 对于每个叶子,互相连一条边即可:若最后剩下一个,则去和根节点连边: 所以叶子节点数+1再/2即答案. 代 ...
- POJ2182(排队问题)
Lost Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10695 Accepted: 6865 Descri ...
- Global 全局样式基本设置
1. 默认字体设置,边距设置 html { font-family: sans-serif; /* 默认字体 */ font-size: 100%; /* 在用户调整窗口大小时,字体大小做相应调整. ...
- ng2中router-outlet用法
说明:router-outlet 是应用中的路由插座,一个页面中可以使用一个或多个router-outlet 1.只使用一个router-outlet 父组件: <router-outlet&g ...
- 第一章 Git 一览
虽然这个系列的文章主要关注的是Github,然而首先了解下Git的基本概念和名词也是非常有帮助的. 工作目录(Working Directory) 工作目录是你个人计算机上的一个目录.在该目录下,每一 ...
- javascript getAttribute
var nodes = document.getElementsByTagName("script"); var node = nodes[nodes.length - 1]; v ...
- git for eclipse 如何取消误操作的忽略(ignore)操作
直接删除ignore文件即可.如下显示: 原文引用:https://blog.csdn.net/exceptionss/article/details/79082601
- ge lei zi yuan
introduction to OJ http://acdream.info/topic/101 ji suan ji he mo ban http://wenku.baidu.com/link?ur ...