11using UnityEngine ;
22using UnityEditor ;
33using System ;
4- using System . Linq ;
54
65namespace UInspectorPlus {
76 internal class InspectorChildWindow : EditorWindow {
@@ -11,20 +10,15 @@ internal class InspectorChildWindow: EditorWindow {
1110 private bool updateProps ;
1211 private bool isReadOnly ;
1312
14- public static void Open ( object target , bool showProps , bool showPrivate , bool showObsolete , bool showMethods , bool updateProps , MethodPropertyDrawer parent ) {
15- CreateInstance < InspectorChildWindow > ( )
16- . InternalOpen ( target , target . GetType ( ) , showProps , showPrivate , showObsolete , showMethods , updateProps , parent ) ;
17- }
13+ public static void Open ( object target , bool showProps , bool showPrivate , bool showObsolete , bool showMethods , bool updateProps , MethodPropertyDrawer parent ) =>
14+ CreateInstance < InspectorChildWindow > ( ) . InternalOpen ( target , target . GetType ( ) , showProps , showPrivate , showObsolete , showMethods , updateProps , parent ) ;
1815
19- public static void OpenStatic ( Type targetType , bool showProps , bool showPrivate , bool showObsolete , bool showMethods , bool updateProps , MethodPropertyDrawer parent )
20- {
21- CreateInstance < InspectorChildWindow > ( )
22- . InternalOpen ( null , targetType , showProps , showPrivate , showObsolete , showMethods , updateProps , parent ) ;
23- }
16+ public static void OpenStatic ( Type targetType , bool showProps , bool showPrivate , bool showObsolete , bool showMethods , bool updateProps , MethodPropertyDrawer parent ) =>
17+ CreateInstance < InspectorChildWindow > ( ) . InternalOpen ( null , targetType , showProps , showPrivate , showObsolete , showMethods , updateProps , parent ) ;
2418
2519 private void InternalOpen ( object target , Type targetType , bool showProps , bool showPrivate , bool showObsolete , bool showMethods , bool updateProps , MethodPropertyDrawer parent ) {
26- titleContent = new GUIContent ( string . Format ( "{0 } - Inspector+", target ?? targetType ) ) ;
27- drawer = new InspectorDrawer ( target , targetType , true , showProps , showPrivate , showObsolete , showMethods ) ;
20+ titleContent = new GUIContent ( $ " { target ?? targetType } - Inspector+") ;
21+ drawer = InspectorDrawer . GetDrawer ( target , targetType , true , showProps , showPrivate , showObsolete , showMethods ) ;
2822 drawer . OnRequireRedraw += Repaint ;
2923 this . parent = parent ;
3024 this . updateProps = updateProps ;
@@ -57,31 +51,24 @@ private void OnGUI() {
5751 if ( drawer . changed ) {
5852 drawer . changed = false ;
5953 if ( parent != null && ! parent . IsReadOnly &&
60- ( ( parent . requiredType != null && parent . requiredType . IsValueType ) || parent . Value != drawer . target ) )
61- if ( ! Helper . AssignValue ( parent . Info , parent . Target , drawer . target ) ) {
62- object reverted ;
63- if ( Helper . FetchValue ( parent . Info , parent . Target , out reverted ) )
64- drawer . target = reverted ;
65- }
54+ ( ( parent . requiredType != null && parent . requiredType . IsValueType ) || parent . Value != drawer . target ) &&
55+ ! Helper . AssignValue ( parent . Info , parent . Target , drawer . target ) && Helper . FetchValue ( parent . Info , parent . Target , out var reverted ) )
56+ drawer . target = reverted ;
6657 }
6758 GUILayout . FlexibleSpace ( ) ;
6859 GUILayout . EndScrollView ( ) ;
6960 }
7061
62+ private void OnDestroy ( ) {
63+ drawer . Dispose ( ) ;
64+ }
65+
7166 private void OnInspectorUpdate ( ) {
7267 if ( EditorGUIUtility . editingTextField )
7368 return ;
7469 UpdateValues ( ) ;
7570 }
7671
77- private void UpdateValues ( ) {
78- drawer . UpdateValues ( updateProps ) ;
79- }
80-
81- private void IterateDrawers < T > ( Action < T > each ) where T : IReflectorDrawer
82- {
83- foreach ( var methodDrawer in drawer . drawer . OfType < T > ( ) )
84- each ( methodDrawer ) ;
85- }
72+ private void UpdateValues ( ) => drawer . UpdateValues ( updateProps ) ;
8673 }
8774}
0 commit comments