11using UnityEngine ;
22using UnityEditor ;
33using UnityEditor . AnimatedValues ;
4+ using UnityEditor . Experimental . GraphView ;
45using System ;
56using System . Collections . Generic ;
67using System . Linq ;
@@ -14,15 +15,14 @@ internal class ComponentMethodDrawer: IReflectorDrawer, IDisposable {
1415 private AnimBool showMethodOptions ;
1516 private AnimBool showMethodSelector ;
1617 private AnimBool showResultSelector ;
17- private string [ ] methodNames ;
18+ private readonly List < SearchTreeEntry > methodNames = new List < SearchTreeEntry > ( ) ;
1819 private int selectedMethodIndex ;
1920 private MemberInfo selectedMember , resolvedMember ;
2021 private ParameterInfo [ ] parameterInfo ;
2122 private MethodPropertyDrawer [ ] parameters ;
2223 private TypeResolverGUI typeResolver ;
2324 private MethodPropertyDrawer result ;
2425 private Exception thrownException ;
25- private string filter ;
2626 private readonly Type ctorType , targetType ;
2727 private bool titleFolded = true , paramsFolded = true , resultFolded = true ,
2828 drawHeader = true , privateFields = true , obsolete = true ;
@@ -95,15 +95,6 @@ public ComponentMethodDrawer(Type type)
9595 InitComponentMethods ( ) ;
9696 }
9797
98- public string Filter {
99- get { return filter ; }
100- set {
101- if ( filter == value ) return ;
102- filter = value ;
103- InitComponentMethods ( false ) ;
104- }
105- }
106-
10798 public void Call ( ) {
10899 var member = resolvedMember ?? selectedMember ;
109100 if ( member == null || parameters == null )
@@ -214,17 +205,21 @@ public bool UpdateValue() {
214205 return false ;
215206 }
216207
208+ public void ShowSearchPopup ( ) => SearchWindowProvider . OpenSearchWindow ( methodNames , i => {
209+ selectedMethodIndex = ( int ) i ;
210+ InitMethodParams ( ) ;
211+ showMethodOptions . target = true ;
212+ RequireRedraw ( ) ;
213+ } ) ;
214+
217215 public void Dispose ( ) {
218216 if ( parameters != null )
219217 foreach ( var parameter in parameters )
220218 parameter . Dispose ( ) ;
221219 result ? . Dispose ( ) ;
222220 }
223221
224- private bool FilterMemberInfo ( MemberInfo m ) =>
225- ( obsolete || ! Attribute . IsDefined ( m , typeof ( ObsoleteAttribute ) ) ) &&
226- ( string . IsNullOrEmpty ( filter ) ||
227- m . Name . IndexOf ( filter , StringComparison . CurrentCultureIgnoreCase ) >= 0 ) ;
222+ private bool FilterMemberInfo ( MemberInfo m ) => obsolete || ! Attribute . IsDefined ( m , typeof ( ObsoleteAttribute ) ) ;
228223
229224 private void AddComponentMethod ( Type type ) {
230225 BindingFlags flag = BindingFlags . Static | BindingFlags . Public | BindingFlags . FlattenHierarchy ;
@@ -289,23 +284,41 @@ where FilterMemberInfo(m)
289284
290285 private void InitComponentMethods ( bool resetIndex = true ) {
291286 methods . Clear ( ) ;
287+ methodNames . Clear ( ) ;
292288 switch ( mode ) {
293289 case MethodMode . Constructor :
294290 AddComponentMethod ( ctorType ) ;
295- methodNames = methods . Select ( ( m , i ) => GetMethodNameFormatted ( m , i ) ) . ToArray ( ) ;
291+ methodNames . Add ( new SearchTreeGroupEntry ( new GUIContent ( "Constructors" ) ) ) ;
292+ methodNames . AddRange ( methods . Select ( ( m , i ) => new SearchTreeEntry ( new GUIContent ( GetMethodNameFormatted ( m ) ) ) { userData = i , level = 1 } ) ) ;
296293 break ;
297294 default :
298295 AddComponentMethod ( component , targetType ) ;
299296 break ;
300297 }
298+ methodNames . Add ( new SearchTreeGroupEntry ( new GUIContent ( "Methods" ) ) ) ;
301299 if ( drawHeader ) {
302300 var gameObject = component as GameObject ;
303301 if ( gameObject != null )
304302 foreach ( var c in gameObject . GetComponents ( typeof ( Component ) ) )
305303 AddComponentMethod ( c ) ;
306- methodNames = methods . Select ( ( m , i ) => $ "{ m . target . GetType ( ) . Name } ({ m . target . ObjIdOrHashCode ( ) } )/{ GetMethodNameFormatted ( m , i ) } ") . ToArray ( ) ;
304+ var temp = new Dictionary < object , List < SearchTreeEntry > > ( ) ;
305+ for ( int i = 0 ; i < methods . Count ; i ++ ) {
306+ ComponentMethod m = methods [ i ] ;
307+ temp . GetValueOrDefault ( m . target ) . Add (
308+ new SearchTreeEntry ( new GUIContent ( GetMethodNameFormatted ( m ) ) ) {
309+ userData = i ,
310+ level = 2 ,
311+ }
312+ ) ;
313+ }
314+ foreach ( var kv in temp ) {
315+ methodNames . Add ( new SearchTreeGroupEntry (
316+ new GUIContent ( $ "{ kv . Key . GetType ( ) . Name } ({ kv . Key . ObjIdOrHashCode ( ) } )") , 1
317+ ) ) ;
318+ methodNames . AddRange ( kv . Value ) ;
319+ }
307320 } else {
308- methodNames = methods . Select ( ( m , i ) => GetMethodNameFormatted ( m , i ) ) . ToArray ( ) ;
321+ methodNames . AddRange ( methods . Select ( ( m , i ) => new SearchTreeEntry ( new GUIContent ( GetMethodNameFormatted ( m ) ) ) { userData = i , level = 1 } ) ) ;
309322 }
310323 if ( ! resetIndex && selectedMember != null ) {
311324 selectedMethodIndex = methods . FindIndex ( m => m . member == selectedMember ) ;
@@ -320,7 +333,7 @@ private void InitComponentMethods(bool resetIndex = true) {
320333 thrownException = null ;
321334 }
322335
323- private string GetMethodNameFormatted ( ComponentMethod m , int i ) {
336+ private string GetMethodNameFormatted ( ComponentMethod m ) {
324337 string name , formatStr ;
325338 ParameterInfo [ ] parameters ;
326339 switch ( m . mode ) {
@@ -392,7 +405,9 @@ private void CreateDrawers() {
392405 private void DrawComponent ( ) {
393406 if ( OnClose != null )
394407 EditorGUILayout . BeginHorizontal ( ) ;
395- selectedMethodIndex = EditorGUILayout . Popup ( mode . ToString ( ) , selectedMethodIndex , methodNames ) ;
408+ EditorGUILayout . PrefixLabel ( mode . ToString ( ) ) ;
409+ if ( GUILayout . Button ( selectedMethodIndex < 0 ? GUIContent . none : methodNames [ selectedMethodIndex ] . content , EditorStyles . popup ) )
410+ ShowSearchPopup ( ) ;
396411 if ( OnClose != null ) {
397412 if ( GUILayout . Button ( EditorGUIUtility . IconContent ( "Toolbar Minus" ) , EditorStyles . miniLabel , GUILayout . ExpandWidth ( false ) ) )
398413 OnClose ( ) ;
0 commit comments