@@ -26,6 +26,8 @@ public class EvaluateWidget : IPooledObject
26
26
private GameObject argHolder ;
27
27
private readonly List < GameObject > argRows = new List < GameObject > ( ) ;
28
28
private readonly List < Text > argLabels = new List < Text > ( ) ;
29
+ private readonly List < InputFieldRef > argInputFields = new List < InputFieldRef > ( ) ;
30
+ private readonly List < Dropdown > argDropdowns = new List < Dropdown > ( ) ;
29
31
30
32
private Type [ ] genericArguments ;
31
33
private string [ ] genericInput ;
@@ -34,9 +36,6 @@ public class EvaluateWidget : IPooledObject
34
36
private readonly List < GameObject > genericArgRows = new List < GameObject > ( ) ;
35
37
private readonly List < Text > genericArgLabels = new List < Text > ( ) ;
36
38
private readonly List < TypeCompleter > genericAutocompleters = new List < TypeCompleter > ( ) ;
37
-
38
- //private readonly List<InputFieldRef> inputFields = new List<InputFieldRef>();
39
- private readonly List < InputFieldRef > argInputFields = new List < InputFieldRef > ( ) ;
40
39
private readonly List < InputFieldRef > genericInputFields = new List < InputFieldRef > ( ) ;
41
40
42
41
public void OnBorrowedFromPool ( CacheMember owner )
@@ -52,6 +51,8 @@ public void OnBorrowedFromPool(CacheMember owner)
52
51
SetArgRows ( ) ;
53
52
54
53
this . UIRoot . SetActive ( true ) ;
54
+
55
+ InspectorManager . OnInspectedTabsChanged += InspectorManager_OnInspectedTabsChanged ;
55
56
}
56
57
57
58
public void OnReturnToPool ( )
@@ -62,6 +63,17 @@ public void OnReturnToPool()
62
63
input . Text = "" ;
63
64
64
65
this . Owner = null ;
66
+
67
+ InspectorManager . OnInspectedTabsChanged -= InspectorManager_OnInspectedTabsChanged ;
68
+ }
69
+
70
+ private void InspectorManager_OnInspectedTabsChanged ( )
71
+ {
72
+ for ( int i = 0 ; i < argDropdowns . Count ; i ++ )
73
+ {
74
+ var drop = argDropdowns [ i ] ;
75
+ PopulateNonPrimitiveArgumentDropdown ( drop , i ) ;
76
+ }
65
77
}
66
78
67
79
public Type [ ] TryParseGenericArguments ( )
@@ -83,33 +95,62 @@ public object[] TryParseArguments()
83
95
84
96
for ( int i = 0 ; i < arguments . Length ; i ++ )
85
97
{
86
- var arg = arguments [ i ] ;
87
- var input = argumentInput [ i ] ;
98
+ var paramInfo = arguments [ i ] ;
88
99
89
- var type = arg . ParameterType ;
90
- if ( type . IsByRef )
91
- type = type . GetElementType ( ) ;
100
+ var argType = paramInfo . ParameterType ;
101
+ if ( argType . IsByRef )
102
+ argType = argType . GetElementType ( ) ;
92
103
93
- if ( type == typeof ( string ) )
104
+ if ( ParseUtility . CanParse ( argType ) )
94
105
{
95
- outArgs [ i ] = input ;
96
- continue ;
97
- }
98
-
99
- if ( string . IsNullOrEmpty ( input ) )
100
- {
101
- if ( arg . IsOptional )
102
- outArgs [ i ] = arg . DefaultValue ;
103
- else
106
+ var input = argumentInput [ i ] ;
107
+
108
+ if ( argType == typeof ( string ) )
109
+ {
110
+ outArgs [ i ] = input ;
111
+ continue ;
112
+ }
113
+
114
+ if ( string . IsNullOrEmpty ( input ) )
115
+ {
116
+ if ( paramInfo . IsOptional )
117
+ outArgs [ i ] = paramInfo . DefaultValue ;
118
+ else
119
+ outArgs [ i ] = null ;
120
+ continue ;
121
+ }
122
+
123
+ if ( ! ParseUtility . TryParse ( input , argType , out outArgs [ i ] , out Exception ex ) )
124
+ {
104
125
outArgs [ i ] = null ;
105
- continue ;
126
+ ExplorerCore . LogWarning ( $ "Cannot parse argument '{ paramInfo . Name } ' ({ paramInfo . ParameterType . Name } )" +
127
+ $ "{ ( ex == null ? "" : $ ", { ex . GetType ( ) . Name } : { ex . Message } ") } ") ;
128
+ }
106
129
}
107
-
108
- if ( ! ParseUtility . TryParse ( input , type , out outArgs [ i ] , out Exception ex ) )
130
+ else
109
131
{
110
- outArgs [ i ] = null ;
111
- ExplorerCore . LogWarning ( $ "Cannot parse argument '{ arg . Name } ' ({ arg . ParameterType . Name } )" +
112
- $ "{ ( ex == null ? "" : $ ", { ex . GetType ( ) . Name } : { ex . Message } ") } ") ;
132
+ var dropdown = argDropdowns [ i ] ;
133
+ if ( dropdown . value == 0 )
134
+ {
135
+ outArgs [ i ] = null ;
136
+ }
137
+ else
138
+ {
139
+ // Probably should do this in a better way...
140
+ // Parse the text of the dropdown option to get the inspector tab index.
141
+ string tabIndexString = "" ;
142
+ for ( int j = 4 ; ; j ++ )
143
+ {
144
+ char c = dropdown . options [ dropdown . value ] . text [ j ] ;
145
+ if ( c == ':' )
146
+ break ;
147
+ tabIndexString += c ;
148
+ }
149
+ int tabIndex = int . Parse ( tabIndexString ) ;
150
+ var tab = InspectorManager . Inspectors [ tabIndex - 1 ] ;
151
+
152
+ outArgs [ i ] = tab . Target ;
153
+ }
113
154
}
114
155
}
115
156
@@ -195,25 +236,54 @@ private void SetNormalArgRows()
195
236
}
196
237
197
238
var arg = arguments [ i ] ;
198
-
239
+ var argType = arg . ParameterType ;
240
+ if ( argType . IsByRef )
241
+ argType = argType . GetElementType ( ) ;
199
242
200
243
if ( i >= argRows . Count )
201
244
AddArgRow ( i , false ) ;
202
245
203
246
argRows [ i ] . SetActive ( true ) ;
204
- argLabels [ i ] . text = $ "{ SignatureHighlighter . Parse ( arg . ParameterType , false ) } <color={ SignatureHighlighter . LOCAL_ARG } >{ arg . Name } </color>";
205
- if ( arg . ParameterType == typeof ( string ) )
206
- argInputFields [ i ] . PlaceholderText . text = "" ;
247
+ argLabels [ i ] . text =
248
+ $ "{ SignatureHighlighter . Parse ( argType , false ) } <color={ SignatureHighlighter . LOCAL_ARG } >{ arg . Name } </color>";
249
+
250
+ if ( ParseUtility . CanParse ( argType ) )
251
+ {
252
+ argInputFields [ i ] . Component . gameObject . SetActive ( true ) ;
253
+ argDropdowns [ i ] . gameObject . SetActive ( false ) ;
254
+
255
+ if ( arg . ParameterType == typeof ( string ) )
256
+ argInputFields [ i ] . PlaceholderText . text = "" ;
257
+ else
258
+ argInputFields [ i ] . PlaceholderText . text = $ "eg. { ParseUtility . GetExampleInput ( argType ) } ";
259
+ }
207
260
else
208
261
{
209
- var elemType = arg . ParameterType ;
210
- if ( elemType . IsByRef )
211
- elemType = elemType . GetElementType ( ) ;
212
- argInputFields [ i ] . PlaceholderText . text = $ "eg. { ParseUtility . GetExampleInput ( elemType ) } " ;
262
+ argInputFields [ i ] . Component . gameObject . SetActive ( false ) ;
263
+ argDropdowns [ i ] . gameObject . SetActive ( true ) ;
264
+
265
+ PopulateNonPrimitiveArgumentDropdown ( argDropdowns [ i ] , i ) ;
213
266
}
214
267
}
215
268
}
216
269
270
+ private void PopulateNonPrimitiveArgumentDropdown ( Dropdown dropdown , int argIndex )
271
+ {
272
+ dropdown . options . Clear ( ) ;
273
+ dropdown . options . Add ( new Dropdown . OptionData ( "null" ) ) ;
274
+
275
+ var argType = arguments [ argIndex ] . ParameterType ;
276
+
277
+ int tabIndex = 0 ;
278
+ foreach ( var tab in InspectorManager . Inspectors )
279
+ {
280
+ tabIndex ++ ;
281
+
282
+ if ( argType . IsAssignableFrom ( tab . Target . GetActualType ( ) ) )
283
+ dropdown . options . Add ( new Dropdown . OptionData ( $ "Tab { tabIndex } : { tab . Tab . TabText . text } ") ) ;
284
+ }
285
+ }
286
+
217
287
private void AddArgRow ( int index , bool generic )
218
288
{
219
289
if ( ! generic )
@@ -242,14 +312,29 @@ private void AddArgRow(int index, GameObject parent, List<GameObject> objectList
242
312
inputField . OnValueChanged += ( string val ) => { inputArray [ index ] = val ; } ;
243
313
244
314
if ( ! generic )
315
+ {
316
+ var dropdownObj = UIFactory . CreateDropdown ( horiGroup , out Dropdown dropdown , "Select argument..." , 14 , ( int val ) =>
317
+ {
318
+ ArgDropdownChanged ( index , val ) ;
319
+ } ) ;
320
+ UIFactory . SetLayoutElement ( dropdownObj , minHeight : 25 , flexibleHeight : 50 , minWidth : 100 , flexibleWidth : 1000 ) ;
321
+ dropdownObj . AddComponent < ContentSizeFitter > ( ) . verticalFit = ContentSizeFitter . FitMode . PreferredSize ;
322
+
245
323
argInputFields . Add ( inputField ) ;
324
+ argDropdowns . Add ( dropdown ) ;
325
+ }
246
326
else
247
327
genericInputFields . Add ( inputField ) ;
248
328
249
329
if ( generic )
250
330
genericAutocompleters . Add ( new TypeCompleter ( null , inputField ) ) ;
251
331
}
252
332
333
+ private void ArgDropdownChanged ( int argIndex , int value )
334
+ {
335
+ // not sure if necessary
336
+ }
337
+
253
338
public GameObject CreateContent ( GameObject parent )
254
339
{
255
340
UIRoot = UIFactory . CreateVerticalGroup ( parent , "EvaluateWidget" , false , false , true , true , 3 , new Vector4 ( 2 , 2 , 2 , 2 ) ,
0 commit comments