Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
guo450212436
et
提交
c8083a73
E
et
项目概览
guo450212436
/
et
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
et
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c8083a73
编写于
5月 08, 2018
作者:
T
tanghai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加unity Log重定向功能。author: NOW
上级
7fc9924e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
126 addition
and
4 deletion
+126
-4
Unity/Assets/Editor/LogRedirection.cs
Unity/Assets/Editor/LogRedirection.cs
+106
-0
Unity/Assets/Editor/LogRedirection.cs.meta
Unity/Assets/Editor/LogRedirection.cs.meta
+12
-0
Unity/Unity.Editor.csproj
Unity/Unity.Editor.csproj
+8
-4
未找到文件。
Unity/Assets/Editor/LogRedirection.cs
0 → 100644
浏览文件 @
c8083a73
using
System.Reflection
;
using
System.Text.RegularExpressions
;
using
UnityEditor
;
using
UnityEditor.Callbacks
;
using
UnityEditorInternal
;
using
UnityEngine
;
/// <summary>
/// 日志重定向相关的实用函数。
/// author: NOW
/// Time: 20180226
/// </summary>
internal
static
class
LogRedirection
{
private
static
readonly
Regex
LogRegex
=
new
Regex
(
@" \(at (.+)\:(\d+)\)\r?\n"
);
[
OnOpenAsset
(
0
)]
private
static
bool
OnOpenAsset
(
int
instanceId
,
int
line
)
{
string
selectedStackTrace
=
GetSelectedStackTrace
();
if
(
string
.
IsNullOrEmpty
(
selectedStackTrace
))
{
return
false
;
}
if
(!
selectedStackTrace
.
Contains
(
"Model.Log"
))
{
return
false
;
}
Match
match
=
LogRegex
.
Match
(
selectedStackTrace
);
if
(!
match
.
Success
)
{
return
false
;
}
// 跳过第一次匹配的堆栈
match
=
match
.
NextMatch
();
if
(!
match
.
Success
)
{
return
false
;
}
if
(!
selectedStackTrace
.
Contains
(
"Hotfix.Log"
))
{
InternalEditorUtility
.
OpenFileAtLineExternal
(
Application
.
dataPath
.
Replace
(
"Assets"
,
""
)
+
match
.
Groups
[
1
].
Value
,
int
.
Parse
(
match
.
Groups
[
2
].
Value
));
return
true
;
}
else
{
// 跳过第2次匹配的堆栈
match
=
match
.
NextMatch
();
if
(!
match
.
Success
)
{
return
false
;
}
InternalEditorUtility
.
OpenFileAtLineExternal
(
Application
.
dataPath
.
Replace
(
"Assets"
,
""
)
+
match
.
Groups
[
1
].
Value
,
int
.
Parse
(
match
.
Groups
[
2
].
Value
));
return
true
;
}
}
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
);
}
}
\ No newline at end of file
Unity/Assets/Editor/LogRedirection.cs.meta
0 → 100644
浏览文件 @
c8083a73
fileFormatVersion: 2
guid: 311d256107e00ed4bbdd3f0d81922b82
timeCreated: 1525772883
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Unity/Unity.Editor.csproj
浏览文件 @
c8083a73
...
...
@@ -12,13 +12,16 @@
<ProjectTypeGuids>
{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
</ProjectTypeGuids>
<TargetFrameworkIdentifier>
.NETFramework
</TargetFrameworkIdentifier>
<TargetFrameworkVersion>
v4.6
</TargetFrameworkVersion>
<TargetFrameworkProfile></TargetFrameworkProfile>
<CompilerResponseFile></CompilerResponseFile>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<CompilerResponseFile>
</CompilerResponseFile>
<UnityProjectGenerator>
VSTU
</UnityProjectGenerator>
<UnityProjectType>
Editor:5
</UnityProjectType>
<UnityBuildTarget>
StandaloneWindows:5
</UnityBuildTarget>
<UnityVersion>
2017.1.3p2
</UnityVersion>
<RootNamespace></RootNamespace>
<RootNamespace>
</RootNamespace>
<LangVersion>
6
</LangVersion>
</PropertyGroup>
<PropertyGroup>
...
...
@@ -213,6 +216,7 @@
<Compile
Include=
"Assets\Editor\GlobalConfigEditor\GlobalConfigEditor.cs"
/>
<Compile
Include=
"Assets\Editor\Helper\EditorResHelper.cs"
/>
<Compile
Include=
"Assets\Editor\Helper\MongoHelper.cs"
/>
<Compile
Include=
"Assets\Editor\LogRedirection.cs"
/>
<Compile
Include=
"Assets\Editor\Proto2CsEditor\Proto2CSEditor.cs"
/>
<Compile
Include=
"Assets\Editor\ReferenceCollectorEditor\ReferenceCollectorEditor.cs"
/>
<Compile
Include=
"Assets\Editor\RsyncEditor\RsyncConfig.cs"
/>
...
...
@@ -241,4 +245,4 @@
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<Target
Name=
"GenerateTargetFrameworkMonikerAttribute"
/>
</Project>
</Project>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录