@@ -37,19 +37,19 @@ public static void RegisterCustomInspectorDrawer<T>(Type targetType, int priorit
3737 }
3838
3939 public static InspectorDrawer GetDrawer ( object target , Type targetType , bool shown , bool showProps , bool showPrivateFields , bool showObsolete , bool showMethods ) {
40- foreach ( var type in AppDomain . CurrentDomain . GetAssemblies ( )
40+ foreach ( var type in AppDomain . CurrentDomain . GetAssemblies ( )
4141 . SelectMany ( asm => asm . GetTypes ( ) )
4242 . Where ( type => type . IsClass && ! type . IsAbstract && type . IsSubclassOf ( typeof ( InspectorDrawer ) ) ) )
4343 RuntimeHelpers . RunClassConstructor ( type . TypeHandle ) ;
4444 int lastPriority = int . MinValue ;
4545 Type drawerType = null ;
4646 try {
47- foreach ( var kv in typedDrawers )
48- if ( kv . targetType . IsAssignableFrom ( targetType ) && kv . priority > lastPriority )
47+ foreach ( var kv in typedDrawers )
48+ if ( kv . targetType . IsAssignableFrom ( targetType ) && kv . priority > lastPriority )
4949 drawerType = kv . drawerType ;
50- if ( drawerType != null )
50+ if ( drawerType != null )
5151 return Activator . CreateInstance ( drawerType , target , targetType , shown , showProps , showPrivateFields , showObsolete , showMethods ) as InspectorDrawer ;
52- } catch ( Exception ex ) {
52+ } catch ( Exception ex ) {
5353 Debug . LogException ( ex ) ;
5454 Debug . LogWarning ( $ "Failed to instaniate drawer { drawerType . Name } , will fall back to default drawer.") ;
5555 }
@@ -59,52 +59,52 @@ public static InspectorDrawer GetDrawer(object target, Type targetType, bool sho
5959 public InspectorDrawer ( object target , Type targetType , bool shown , bool showProps , bool showPrivateFields , bool showObsolete , bool showMethods ) {
6060 this . target = target ;
6161 BindingFlags flag = BindingFlags . Static | BindingFlags . Public ;
62- if ( target != null )
62+ if ( target != null )
6363 flag |= BindingFlags . Instance ;
64- if ( allowPrivate = showPrivateFields )
64+ if ( allowPrivate = showPrivateFields )
6565 flag |= BindingFlags . NonPublic ;
6666 this . targetType = targetType ;
6767 var fields = targetType . GetFields ( flag ) ;
6868 var props = ! showProps ? null : targetType . GetProperties ( flag ) . Where ( prop => prop . GetIndexParameters ( ) . Length == 0 ) . ToArray ( ) ;
6969 isInternalType = ! targetType . IsSubclassOf ( typeof ( MonoBehaviour ) ) || Attribute . IsDefined ( targetType , typeof ( ExecuteInEditMode ) ) ;
70- foreach ( var field in fields )
70+ foreach ( var field in fields )
7171 try {
72- if ( ! showObsolete && Attribute . IsDefined ( field , typeof ( ObsoleteAttribute ) ) )
72+ if ( ! showObsolete && Attribute . IsDefined ( field , typeof ( ObsoleteAttribute ) ) )
7373 continue ;
7474 drawer . Add ( new MethodPropertyDrawer ( field , target , showPrivateFields , showObsolete ) {
7575 AllowReferenceMode = false
7676 } ) ;
77- } catch ( Exception ex ) {
77+ } catch ( Exception ex ) {
7878 Debug . LogException ( ex ) ;
7979 }
80- if ( showProps ) {
80+ if ( showProps ) {
8181 HashSet < string > blacklistedType ;
82- if ( ! Helper . blackListedTypes . TryGetValue ( targetType , out blacklistedType ) ) {
82+ if ( ! Helper . blackListedTypes . TryGetValue ( targetType , out blacklistedType ) ) {
8383 Helper . blackListedTypes . Add ( targetType , blacklistedType = new HashSet < string > ( ) ) ;
84- foreach ( var kvp in Helper . blackListedTypes )
85- if ( kvp . Key . IsAssignableFrom ( targetType ) )
84+ foreach ( var kvp in Helper . blackListedTypes )
85+ if ( kvp . Key . IsAssignableFrom ( targetType ) )
8686 blacklistedType . UnionWith ( kvp . Value ) ;
8787 }
88- foreach ( var prop in props )
88+ foreach ( var prop in props )
8989 try {
90- if ( blacklistedType != null && blacklistedType . Contains ( prop . Name ) )
90+ if ( blacklistedType != null && blacklistedType . Contains ( prop . Name ) )
9191 continue ;
92- if ( ! showObsolete && Attribute . IsDefined ( prop , typeof ( ObsoleteAttribute ) ) )
92+ if ( ! showObsolete && Attribute . IsDefined ( prop , typeof ( ObsoleteAttribute ) ) )
9393 continue ;
9494 drawer . Add ( new MethodPropertyDrawer ( prop , target , showPrivateFields , showObsolete , prop . CanRead && EditorApplication . isPlaying ) {
9595 AllowReferenceMode = false ,
9696 Updatable = isInternalType || Helper . GetState ( prop , false ) ,
9797 ShowUpdatable = ! isInternalType
9898 } ) ;
99- } catch ( Exception ex ) {
99+ } catch ( Exception ex ) {
100100 Debug . LogException ( ex ) ;
101101 }
102102 }
103- if ( allowMethods = showMethods )
103+ if ( allowMethods = showMethods )
104104 AddMethodMenu ( ) ;
105- foreach ( var d in drawer )
105+ foreach ( var d in drawer )
106106 d . OnRequireRedraw += RequireRedraw ;
107- if ( target != null )
107+ if ( target != null )
108108 this . shown = Helper . GetState ( target , shown ) ;
109109 }
110110
@@ -118,11 +118,11 @@ private void AddMethodMenu() {
118118 }
119119
120120 public void Draw ( bool drawHeader = true , bool readOnly = false ) {
121- if ( drawHeader ) {
121+ if ( drawHeader ) {
122122 shown = EditorGUILayout . InspectorTitlebar ( shown , target as UnityObject ) ;
123- if ( target != null )
123+ if ( target != null )
124124 Helper . StoreState ( target , shown ) ;
125- if ( ! shown )
125+ if ( ! shown )
126126 return ;
127127 }
128128 EditorGUI . indentLevel ++ ;
@@ -131,80 +131,81 @@ public void Draw(bool drawHeader = true, bool readOnly = false) {
131131 Draw ( readOnly ) ;
132132 EditorGUILayout . EndVertical ( ) ;
133133 EditorGUI . indentLevel -- ;
134- if ( removingDrawers . Count > 0 ) {
135- foreach ( var drawer in removingDrawers )
136- if ( drawer is IDisposable disposable )
134+ if ( removingDrawers . Count > 0 ) {
135+ foreach ( var drawer in removingDrawers )
136+ if ( drawer is IDisposable disposable )
137137 disposable . Dispose ( ) ;
138138 drawer . RemoveAll ( removingDrawers . Contains ) ;
139139 removingDrawers . Clear ( ) ;
140140 }
141141 }
142142
143143 protected virtual void Draw ( bool readOnly ) {
144- foreach ( var item in drawer ) {
144+ foreach ( var item in drawer ) {
145145 var methodDrawer = item as ComponentMethodDrawer ;
146146 var fieldDrawer = item as MethodPropertyDrawer ;
147- if ( methodDrawer != null ) {
147+ if ( methodDrawer != null ) {
148148 EditorGUI . indentLevel -- ;
149149 EditorGUILayout . BeginHorizontal ( ) ;
150150 EditorGUILayout . LabelField ( GUIContent . none , GUILayout . Width ( EditorGUIUtility . singleLineHeight ) ) ;
151151 EditorGUILayout . BeginVertical ( ) ;
152+ methodDrawer . Filter = searchText ;
152153 methodDrawer . Draw ( ) ;
153154 EditorGUILayout . EndVertical ( ) ;
154155 EditorGUILayout . EndHorizontal ( ) ;
155156 EditorGUI . indentLevel ++ ;
156- } else if ( item != null ) {
157- if ( item . Info != null && ! string . IsNullOrEmpty ( searchText ) && item . Info . Name . IndexOf ( searchText , StringComparison . CurrentCultureIgnoreCase ) < 0 )
157+ } else if ( item != null ) {
158+ if ( item . Info != null && ! string . IsNullOrEmpty ( searchText ) && item . Info . Name . IndexOf ( searchText , StringComparison . CurrentCultureIgnoreCase ) < 0 )
158159 continue ;
159- if ( fieldDrawer != null )
160+ if ( fieldDrawer != null )
160161 fieldDrawer . Draw ( readOnly ) ;
161162 else
162163 item . Draw ( ) ;
163164 changed |= item . UpdateIfChanged ( ) ;
164165 }
165166 }
166- if ( allowMethods ) {
167+ if ( allowMethods ) {
167168 GUILayout . BeginHorizontal ( ) ;
168169 GUILayout . FlexibleSpace ( ) ;
169- if ( GUILayout . Button ( new GUIContent ( "+" , "Add Method / Index Properties Watcher" ) , EditorStyles . miniButton , GUILayout . ExpandWidth ( false ) ) )
170+ if ( GUILayout . Button ( new GUIContent ( "+" , "Add Method / Index Properties Watcher" ) , EditorStyles . miniButton , GUILayout . ExpandWidth ( false ) ) )
170171 AddMethodMenu ( ) ;
171172 GUILayout . EndHorizontal ( ) ;
172173 }
173174 }
174175
175176 private void DrawRequestRefs ( ) {
176177 MethodPropertyDrawer removal = null ;
177- foreach ( var drawer in MethodPropertyDrawer . drawerRequestingReferences )
178- if ( drawer . requiredType . IsAssignableFrom ( targetType ) &&
178+ foreach ( var drawer in MethodPropertyDrawer . drawerRequestingReferences )
179+ if ( drawer . requiredType . IsAssignableFrom ( targetType ) &&
179180 GUILayout . Button ( $ "Assign this object to { drawer . name } ") ) {
180181 drawer . Value = target ;
181182 removal = drawer ;
182183 }
183- if ( removal != null ) MethodPropertyDrawer . drawerRequestingReferences . Remove ( removal ) ;
184+ if ( removal != null ) MethodPropertyDrawer . drawerRequestingReferences . Remove ( removal ) ;
184185 }
185186
186187 public void UpdateValues ( bool updateProps ) {
187- if ( target == null ) return ;
188- foreach ( var drawerItem in drawer ) {
188+ if ( target == null ) return ;
189+ foreach ( var drawerItem in drawer ) {
189190 var propDrawer = drawerItem as MethodPropertyDrawer ;
190- if ( propDrawer == null )
191+ if ( propDrawer == null )
191192 continue ;
192193 var isPropInfo = propDrawer . Info is PropertyInfo ;
193- if ( ! isInternalType && ( ! updateProps || ! propDrawer . Updatable ) && isPropInfo )
194+ if ( ! isInternalType && ( ! updateProps || ! propDrawer . Updatable ) && isPropInfo )
194195 continue ;
195196 propDrawer . UpdateValue ( ) ;
196197 }
197198 }
198199
199200 public virtual void Dispose ( ) {
200- foreach ( var d in drawer )
201- if ( d is IDisposable disposable )
201+ foreach ( var d in drawer )
202+ if ( d is IDisposable disposable )
202203 disposable . Dispose ( ) ;
203204 drawer . Clear ( ) ;
204205 }
205206
206207 protected void RequireRedraw ( ) {
207- if ( target != null && OnRequireRedraw != null )
208+ if ( target != null && OnRequireRedraw != null )
208209 OnRequireRedraw ( ) ;
209210 }
210211 }
0 commit comments