From 055268154fa0e4e4e8b97faf269bc1a0ce9f8303 Mon Sep 17 00:00:00 2001 From: topameng Date: Fri, 9 Aug 2019 18:19:53 +0800 Subject: [PATCH] =?UTF-8?q?1.0.8.588=20=E4=BF=AE=E5=A4=8D=E5=8F=8C?= =?UTF-8?q?=E5=87=BBlog=E8=B7=B3=E8=BD=AC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/ToLua/Core/ToLua.cs | 57 ++++++++++++++--------- Assets/ToLua/Examples/20_utf8/TestUTF8.cs | 2 +- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/Assets/ToLua/Core/ToLua.cs b/Assets/ToLua/Core/ToLua.cs index b81f08cf..9aa99169 100644 --- a/Assets/ToLua/Core/ToLua.cs +++ b/Assets/ToLua/Core/ToLua.cs @@ -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() { @@ -198,7 +200,7 @@ static int Print(IntPtr L) } } - Debugger.Log(sb.ToString()); //200行与_line一致 + Debugger.Log(sb.ToString()); //203行与_line一致 } return 0; } @@ -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) @@ -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; @@ -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); } @@ -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); } @@ -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; } } @@ -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); diff --git a/Assets/ToLua/Examples/20_utf8/TestUTF8.cs b/Assets/ToLua/Examples/20_utf8/TestUTF8.cs index 4834446a..099d2314 100644 --- a/Assets/ToLua/Examples/20_utf8/TestUTF8.cs +++ b/Assets/ToLua/Examples/20_utf8/TestUTF8.cs @@ -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();