@@ -16,7 +16,9 @@ public class ConsoleWindow : IDebuggerWindow
16
16
//action执行函数
17
17
private Dictionary < string , Action > _commandAction = new Dictionary < string , Action > ( ) ;
18
18
//支持反射
19
- private bool _reflectionsupported = true ;
19
+ private bool _reflectionSupported = true ;
20
+ //支持消息发送
21
+ private bool _sendMessageSupported = true ;
20
22
//显示文本
21
23
private List < string > _showTexts = new List < string > ( ) ;
22
24
//滚动文本的位置坐标
@@ -49,7 +51,8 @@ public void OnDraw()
49
51
{
50
52
ClearLines ( ) ;
51
53
}
52
- _reflectionsupported = GUILayout . Toggle ( _reflectionsupported , "Reflection supported" ) ;
54
+ _reflectionSupported = GUILayout . Toggle ( _reflectionSupported , "Reflection supported" ) ;
55
+ _sendMessageSupported = GUILayout . Toggle ( _sendMessageSupported , "SendMessage supported" ) ;
53
56
GUILayout . EndHorizontal ( ) ;
54
57
55
58
_showScrollPos = GUILayout . BeginScrollView ( _showScrollPos , "box" ) ;
@@ -176,42 +179,57 @@ private void ExecuteCommand(string command)
176
179
MethodInfo callMethod ;
177
180
if ( ! _commandMethod . TryGetValue ( command , out callMethod ) )
178
181
{
179
- if ( _reflectionsupported )
182
+
183
+ int index = command . LastIndexOf ( '.' ) ;
184
+ if ( index > 0 && index < command . Length - 1 )
180
185
{
181
- int index = command . LastIndexOf ( '.' ) ;
182
- if ( index > 0 && index < command . Length - 1 )
186
+ string fullName = command . Substring ( 0 , index ) ;
187
+ index ++ ;
188
+ string methodName = command . Substring ( index , command . Length - index ) ;
189
+ //优先查找反射
190
+ if ( _reflectionSupported )
183
191
{
184
- string typefullName = command . Substring ( 0 , index ) ;
185
- index ++ ;
186
- string methodName = command . Substring ( index , command . Length - index ) ;
187
- Type callType = TypeUtility . AllAssemblyTypes . Find ( x => x . FullName . Equals ( typefullName ) ) ;
192
+ Type callType = TypeUtility . AllAssemblyTypes . Find ( x => x . FullName . Equals ( fullName ) ) ;
188
193
if ( callType != null )
189
194
{
190
195
callMethod = callType . GetMethod ( methodName , BindingFlags . Static | BindingFlags . NonPublic | BindingFlags . Public ) ;
196
+
197
+ if ( callMethod != null )
198
+ {
199
+ bool call = false ;
200
+ var gp = callMethod . GetParameters ( ) ;
201
+ if ( gp . Length == 0 )
202
+ {
203
+ parameters = null ;
204
+ call = true ;
205
+ }
206
+ else if ( gp . Length == parameters . Length )
207
+ {
208
+ call = true ;
209
+ }
210
+ if ( call )
211
+ {
212
+ callMethod . Invoke ( null , parameters ) ;
213
+ return ;
214
+ }
215
+ }
191
216
}
192
217
}
193
- }
194
- }
195
218
196
- if ( callMethod != null )
197
- {
198
- bool call = false ;
199
- var gp = callMethod . GetParameters ( ) ;
200
- if ( gp . Length == 0 )
201
- {
202
- parameters = null ;
203
- call = true ;
204
- }
205
- else if ( gp . Length == parameters . Length )
206
- {
207
- call = true ;
208
- }
209
- if ( call )
210
- {
211
- callMethod . Invoke ( null , parameters ) ;
212
- return ;
219
+ //支持查找GameObject SendMessage
220
+ if ( _sendMessageSupported )
221
+ {
222
+ GameObject findGameObject = GameObject . Find ( fullName ) ;
223
+ if ( findGameObject != null )
224
+ {
225
+ findGameObject . SendMessage ( methodName , args ) ;
226
+ return ;
227
+ }
228
+ }
213
229
}
214
230
}
231
+
232
+
215
233
//添加反馈
216
234
AddLine ( $ "<color=yellow>$ [{ command } ]</color> Can't find command or parameters error!") ;
217
235
}
0 commit comments