1
+ using System . Collections . Generic ;
1
2
using System . Runtime . InteropServices ;
2
3
using GS . Editor ;
3
4
using UnityEditor ;
4
5
using UnityEditor . IMGUI . Controls ;
5
6
using UnityEngine ;
6
7
using UnityEngine . Serialization ;
8
+ using XLua ;
9
+ using XLua . LuaDLL ;
7
10
8
11
namespace GSUnityLuaShell
9
12
{
@@ -65,9 +68,14 @@ private void OnGUI()
65
68
EditorGUILayout . EndHorizontal ( ) ;
66
69
67
70
EditorGUILayout . BeginScrollView ( mScrollPos ) ;
68
- treeView . OnGUI ( new Rect ( 0 , 0 , position . width , position . height - GSUnityLuaShellConst . InputFiledHeight ) ) ;
71
+ treeView . OnGUI ( new Rect ( 0 , 0 , position . width , position . height - GSUnityLuaShellConst . InputFiledHeight - 50 ) ) ;
69
72
EditorGUILayout . EndScrollView ( ) ;
70
73
74
+ //TODO 修复回车导致对于\n
75
+ if ( Text . StartsWith ( "\n " ) )
76
+ {
77
+ Text = Text . Substring ( 1 , Text . Length - 1 ) ;
78
+ }
71
79
mTextEditor = ( TextEditor ) GUIUtility . GetStateObject ( typeof ( TextEditor ) , GUIUtility . keyboardControl ) ;
72
80
mTextEditor . text = Text ;
73
81
GUI . SetNextControlName ( GSUnityLuaShellConst . InputTextAreaControlName ) ;
@@ -87,19 +95,30 @@ public void ParseResult()
87
95
}
88
96
else
89
97
{
90
- foreach ( var obj in objects )
98
+ if ( objects . Length == 1 )
91
99
{
92
- if ( obj == null )
100
+ object result = objects [ 0 ] ;
101
+ if ( result is LuaTable )
93
102
{
94
- treeView . AddChild ( "nil" ) ;
95
- continue ;
103
+ treeView . AddChild ( result . ToString ( ) ) ;
104
+ ParseResultLuaTable ( result as LuaTable , 1 ) ;
105
+ }
106
+ else
107
+ {
108
+ treeView . AddChild ( result == null ? "nil" : result . ToString ( ) ) ;
109
+ }
110
+ }
111
+ else
112
+ {
113
+ foreach ( var obj in objects )
114
+ {
115
+ treeView . AddChild ( obj == null ? "nil" : obj . ToString ( ) ) ;
96
116
}
97
-
98
- treeView . AddChild ( obj . ToString ( ) ) ;
99
117
}
100
118
}
101
119
102
120
treeView . Reload ( ) ;
121
+ treeView . SetSelection ( new List < int > ( ) { treeView . getRoot ( ) . children [ treeView . getRoot ( ) . children . Count - 1 ] . id } , TreeViewSelectionOptions . RevealAndFrame ) ;
103
122
Text = "" ;
104
123
}
105
124
@@ -108,5 +127,42 @@ public void Test(string command)
108
127
Text = command ;
109
128
ParseResult ( ) ;
110
129
}
130
+
131
+ public void ParseResultLuaTable ( LuaTable luaTable , int depth )
132
+ {
133
+ if ( depth >= GSUnityLuaShellConst . LuaTableDepth )
134
+ {
135
+ return ;
136
+ }
137
+
138
+ foreach ( var key in luaTable . GetKeys ( ) )
139
+ {
140
+ var value = luaTable [ key ] ;
141
+ if ( value == null )
142
+ {
143
+ treeView . AddChild ( $ "{ key } nil", false , depth ) ;
144
+ continue ;
145
+ }
146
+ treeView . AddChild ( $ "{ key } { value . ToString ( ) } ", false , depth ) ;
147
+ if ( value is LuaTable )
148
+ {
149
+ ParseResultLuaTable ( value as LuaTable , depth + 1 ) ;
150
+ }
151
+ }
152
+
153
+ for ( int i = 1 ; i <= luaTable . Length ; i ++ )
154
+ {
155
+ object value = luaTable [ i ] ;
156
+ if ( value == null )
157
+ {
158
+ break ;
159
+ }
160
+ treeView . AddChild ( $ "{ value . ToString ( ) } ", false , depth ) ;
161
+ if ( value is LuaTable )
162
+ {
163
+ ParseResultLuaTable ( value as LuaTable , depth + 1 ) ;
164
+ }
165
+ }
166
+ }
111
167
}
112
168
}
0 commit comments