Skip to content

Commit

Permalink
1.0.8.588 修复双击log跳转问题
Browse files Browse the repository at this point in the history
  • Loading branch information
topameng committed Aug 9, 2019
1 parent 796160f commit 0552681
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
57 changes: 34 additions & 23 deletions Assets/ToLua/Core/ToLua.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ public static class ToLua

#if UNITY_EDITOR
static int _instanceID = -1;
static int _line = 201;
static int _line = 203;
private static object consoleWindow;
private static object logListView;
private static FieldInfo logListViewCurrentRow;
private static MethodInfo LogEntriesGetEntry;
private static MethodInfo StartGettingEntries;
private static MethodInfo EndGettingEntries;
private static object logEntry;
private static FieldInfo logEntryCondition;
#endif
private static FieldInfo logEntryCondition;
#endif

static ToLua()
{
Expand Down Expand Up @@ -198,7 +200,7 @@ static int Print(IntPtr L)
}
}

Debugger.Log(sb.ToString()); //200行与_line一致
Debugger.Log(sb.ToString()); //203行与_line一致
}
return 0;
}
Expand Down Expand Up @@ -448,7 +450,7 @@ private static bool GetConsoleWindowListView()
{
Assembly unityEditorAssembly = Assembly.GetAssembly(typeof(EditorWindow));
Type consoleWindowType = unityEditorAssembly.GetType("UnityEditor.ConsoleWindow");
FieldInfo fieldInfo = consoleWindowType.GetField("ms_ConsoleWindow", BindingFlags.Static | BindingFlags.NonPublic);
FieldInfo fieldInfo = consoleWindowType.GetField("ms_ConsoleWindow", BindingFlags.Static | BindingFlags.NonPublic);
consoleWindow = fieldInfo.GetValue(null);

if (consoleWindow == null)
Expand All @@ -461,16 +463,18 @@ private static bool GetConsoleWindowListView()
logListView = listViewFieldInfo.GetValue(consoleWindow);
logListViewCurrentRow = listViewFieldInfo.FieldType.GetField("row", BindingFlags.Instance | BindingFlags.Public);
#if UNITY_2017_1_OR_NEWER
Type logEntriesType = unityEditorAssembly.GetType("UnityEditor.LogEntries");
LogEntriesGetEntry = logEntriesType.GetMethod("GetEntryInternal", BindingFlags.Static | BindingFlags.Public);
Type logEntryType = unityEditorAssembly.GetType("UnityEditor.LogEntry");
Type logEntriesType = unityEditorAssembly.GetType("UnityEditor.LogEntries");
LogEntriesGetEntry = logEntriesType.GetMethod("GetEntryInternal", BindingFlags.Static | BindingFlags.Public);
Type logEntryType = unityEditorAssembly.GetType("UnityEditor.LogEntry");
#else
Type logEntriesType = unityEditorAssembly.GetType("UnityEditorInternal.LogEntries");
LogEntriesGetEntry = logEntriesType.GetMethod("GetEntryInternal", BindingFlags.Static | BindingFlags.Public);
Type logEntryType = unityEditorAssembly.GetType("UnityEditorInternal.LogEntry");
#endif
logEntry = Activator.CreateInstance(logEntryType);
Type logEntryType = unityEditorAssembly.GetType("UnityEditorInternal.LogEntry");
#endif
logEntryCondition = logEntryType.GetField("condition", BindingFlags.Instance | BindingFlags.Public);
StartGettingEntries = logEntriesType.GetMethod("StartGettingEntries", BindingFlags.Static | BindingFlags.Public);
EndGettingEntries = logEntriesType.GetMethod("EndGettingEntries", BindingFlags.Static | BindingFlags.Public);
logEntry = Activator.CreateInstance(logEntryType);
}

return true;
Expand All @@ -479,17 +483,23 @@ private static bool GetConsoleWindowListView()

private static string GetListViewRowCount(ref int line)
{
int row = (int)logListViewCurrentRow.GetValue(logListView);
LogEntriesGetEntry.Invoke(null, new object[] { row, logEntry });
#if UNITY_2017_1_OR_NEWER
object rows = StartGettingEntries.Invoke(null, null);
#endif
int row = (int)logListViewCurrentRow.GetValue(logListView);
LogEntriesGetEntry.Invoke(null, new object[] { row, logEntry });
string condition = logEntryCondition.GetValue(logEntry) as string;
#if UNITY_2017_1_OR_NEWER
EndGettingEntries.Invoke(null, null);
#endif
condition = condition.Substring(0, condition.IndexOf('\n'));
int index = condition.IndexOf(".lua:");
int index = condition.IndexOf(".lua:");

if (index >= 0)
{
int start = condition.IndexOf("[");
int end = condition.IndexOf("]:");
string _line = condition.Substring(index + 5, end - index - 4);
string _line = condition.Substring(index + 5, end - index - 5);
Int32.TryParse(_line, out line);
return condition.Substring(start + 1, index + 3 - start);
}
Expand All @@ -500,7 +510,7 @@ private static string GetListViewRowCount(ref int line)
{
int start = condition.IndexOf("[");
int end = condition.IndexOf("]:");
string _line = condition.Substring(index + 5, end - index - 4);
string _line = condition.Substring(index + 4, end - index - 4);
Int32.TryParse(_line, out line);
return condition.Substring(start + 1, index + 2 - start);
}
Expand Down Expand Up @@ -574,11 +584,12 @@ public static bool OnOpenAsset(int instanceID, int line)
if (path.EndsWith(fileName) || path.EndsWith(fileName + ".bytes"))
{
UnityEngine.Object obj = AssetDatabase.LoadMainAssetAtPath(path);
if (Application.isPlaying) {
EditorApplication.delayCall = delegate(){ AssetDatabase.OpenAsset(obj, line); };
} else {
AssetDatabase.OpenAsset(obj, line);
}
#if !UNITY_2017_1_OR_NEWER
EditorApplication.delayCall += () => { AssetDatabase.OpenAsset(obj, line); };
#else
AssetDatabase.OpenAsset(obj, line);
#endif

return true;
}
}
Expand All @@ -590,9 +601,9 @@ public static bool OnOpenAsset(int instanceID, int line)
}
#endif
#endregion
/*-------------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------------*/

public static string ToString(IntPtr L, int stackPos)
public static string ToString(IntPtr L, int stackPos)
{
LuaTypes luaType = LuaDLL.lua_type(L, stackPos);

Expand Down
2 changes: 1 addition & 1 deletion Assets/ToLua/Examples/20_utf8/TestUTF8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected override void OnLoadFinished()
Application.logMessageReceived += ShowTips;
#endif
base.OnLoadFinished();
luaState.DoString(script);
luaState.DoString(script, "TestUTF8.cs");
LuaFunction func = luaState.GetFunction("Test");
func.Call();
func.Dispose();
Expand Down

0 comments on commit 0552681

Please sign in to comment.