@@ -59,7 +59,7 @@ 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 ( ! Helper . IsInvalid ( target ) )
6363 flag |= BindingFlags . Instance ;
6464 if ( allowPrivate = showPrivateFields )
6565 flag |= BindingFlags . NonPublic ;
@@ -104,7 +104,7 @@ public InspectorDrawer(object target, Type targetType, bool shown, bool showProp
104104 AddMethodMenu ( ) ;
105105 foreach ( var d in drawer )
106106 d . OnRequireRedraw += RequireRedraw ;
107- if ( target != null )
107+ if ( ! Helper . IsInvalid ( target ) )
108108 this . shown = Helper . GetState ( target , shown ) ;
109109 }
110110
@@ -120,7 +120,7 @@ private void AddMethodMenu() {
120120 public void Draw ( bool drawHeader = true , bool readOnly = false ) {
121121 if ( drawHeader ) {
122122 shown = EditorGUILayout . InspectorTitlebar ( shown , target as UnityObject ) ;
123- if ( target != null )
123+ if ( ! Helper . IsInvalid ( target ) )
124124 Helper . StoreState ( target , shown ) ;
125125 if ( ! shown )
126126 return ;
@@ -142,9 +142,7 @@ public void Draw(bool drawHeader = true, bool readOnly = false) {
142142
143143 protected virtual void Draw ( bool readOnly ) {
144144 foreach ( var item in drawer ) {
145- var methodDrawer = item as ComponentMethodDrawer ;
146- var fieldDrawer = item as MethodPropertyDrawer ;
147- if ( methodDrawer != null ) {
145+ if ( item is ComponentMethodDrawer methodDrawer ) {
148146 EditorGUI . indentLevel -- ;
149147 EditorGUILayout . BeginHorizontal ( ) ;
150148 EditorGUILayout . LabelField ( GUIContent . none , GUILayout . Width ( EditorGUIUtility . singleLineHeight ) ) ;
@@ -157,7 +155,7 @@ protected virtual void Draw(bool readOnly) {
157155 } else if ( item != null ) {
158156 if ( item . Info != null && ! string . IsNullOrEmpty ( searchText ) && item . Info . Name . IndexOf ( searchText , StringComparison . CurrentCultureIgnoreCase ) < 0 )
159157 continue ;
160- if ( fieldDrawer != null )
158+ if ( item is MethodPropertyDrawer fieldDrawer )
161159 fieldDrawer . Draw ( readOnly ) ;
162160 else
163161 item . Draw ( ) ;
@@ -184,8 +182,8 @@ private void DrawRequestRefs() {
184182 if ( removal != null ) MethodPropertyDrawer . drawerRequestingReferences . Remove ( removal ) ;
185183 }
186184
187- public void UpdateValues ( bool updateProps ) {
188- if ( target == null ) return ;
185+ public virtual void UpdateValues ( bool updateProps ) {
186+ if ( Helper . IsInvalid ( target ) ) return ;
189187 foreach ( var drawerItem in drawer ) {
190188 var propDrawer = drawerItem as MethodPropertyDrawer ;
191189 if ( propDrawer == null )
@@ -205,7 +203,7 @@ public virtual void Dispose() {
205203 }
206204
207205 protected void RequireRedraw ( ) {
208- if ( target != null && OnRequireRedraw != null )
206+ if ( ! Helper . IsInvalid ( target ) && OnRequireRedraw != null )
209207 OnRequireRedraw ( ) ;
210208 }
211209 }
0 commit comments