@@ -16,6 +16,7 @@ class MethodPropertyDrawer: IReflectorDrawer {
1616 public Type requiredType ;
1717 readonly List < PropertyType > castableTypes ;
1818 PropertyType currentType ;
19+ object target ;
1920 object rawValue ;
2021 bool referenceMode ;
2122 int grabValueMode ;
@@ -36,17 +37,13 @@ class MethodPropertyDrawer: IReflectorDrawer {
3637 bool masked ;
3738 bool showUpdatable ;
3839 bool updatable ;
39- bool arrayShown ;
4040 bool isInfoReadonly ;
4141 bool isStatic ;
4242 bool isPrivate ;
4343 public event Action OnRequireRedraw ;
4444
4545 Exception getException ;
4646
47- readonly List < MethodPropertyDrawer > arrayContentDrawer ;
48- ReorderableList arrayHandler ;
49-
5047 public UnityObject Component {
5148 get { return component ; }
5249 set {
@@ -117,7 +114,7 @@ public bool ReferenceMode {
117114 InitFieldTypes ( ) ;
118115 } else {
119116 rawValue = GetReferencedValue ( ) ;
120- SetArray ( ) ;
117+ // SetArray();
121118 }
122119 selectedFieldIndex = - 1 ;
123120 selectedField = null ;
@@ -160,11 +157,13 @@ public object Value {
160157 get {
161158 if ( referenceMode ) {
162159 rawValue = GetReferencedValue ( ) ;
160+ /*
163161 } else if (currentType == PropertyType.Array) {
164162 var array = Array.CreateInstance(requiredType.GetElementType(), arrayContentDrawer.Count);
165163 for (int i = 0; i < arrayContentDrawer.Count; i++)
166164 array.SetValue(arrayContentDrawer[i].Value, i);
167165 rawValue = array;
166+ */
168167 }
169168 var convertedValue = rawValue ;
170169 if ( rawValue != null && requiredType != typeof ( object ) && requiredType . IsInstanceOfType ( rawValue ) ) {
@@ -180,7 +179,7 @@ public object Value {
180179 set {
181180 rawValue = value ;
182181 changed = false ;
183- SetArray ( ) ;
182+ // SetArray();
184183 }
185184 }
186185
@@ -193,33 +192,45 @@ public Exception GetException {
193192 }
194193 }
195194
195+ public bool IsReadOnly {
196+ get { return isInfoReadonly ; }
197+ }
198+
199+ public object Target {
200+ get { return target ; }
201+ }
202+
196203 private MethodPropertyDrawer ( bool allowPrivate , bool allowObsolete ) {
197204 this . castableTypes = new List < PropertyType > ( ) ;
198205 this . fields = new List < ComponentFields > ( ) ;
199206 this . selectedFieldIndex = - 1 ;
200- this . arrayContentDrawer = new List < MethodPropertyDrawer > ( ) ;
201- this . arrayHandler = new ReorderableList ( arrayContentDrawer , typeof ( MethodPropertyDrawer ) ) ;
202207 this . privateFields = allowPrivate ;
203208 this . obsolete = allowObsolete ;
204209 }
205210
206211 public MethodPropertyDrawer ( FieldInfo field , object target , bool allowPrivate , bool allowObsolete )
207212 : this ( allowPrivate , allowObsolete ) {
213+ this . memberInfo = field ;
214+ this . isInfoReadonly = Helper . IsReadOnly ( field ) ;
208215 this . requiredType = field . FieldType ;
209216 this . name = Helper . GetMemberName ( field , true ) ;
210217 this . nameContent = new GUIContent ( name , Helper . GetMemberName ( field ) ) ;
211218 this . rawValue = field . GetValue ( target ) ;
219+ this . target = target ;
212220 this . isStatic = field . IsStatic ;
213221 this . isPrivate = field . IsPrivate ;
214222 InitType ( ) ;
215223 }
216224
217225 public MethodPropertyDrawer ( PropertyInfo property , object target , bool allowPrivate , bool allowObsolete , bool initValue )
218226 : this ( allowPrivate , allowObsolete ) {
227+ this . memberInfo = property ;
228+ this . isInfoReadonly = Helper . IsReadOnly ( property ) ;
219229 this . requiredType = property . PropertyType ;
220230 this . name = Helper . GetMemberName ( property , true ) ;
221231 this . nameContent = new GUIContent ( name , Helper . GetMemberName ( property ) ) ;
222232 if ( initValue ) this . rawValue = property . GetValue ( target , null ) ;
233+ this . target = target ;
223234 var getMethod = property . GetGetMethod ( ) ;
224235 this . isStatic = getMethod != null ? getMethod . IsStatic : false ;
225236 this . isPrivate = getMethod != null ? getMethod . IsPrivate : false ;
@@ -231,7 +242,8 @@ public MethodPropertyDrawer(ParameterInfo parameter, bool allowPrivate, bool all
231242 this . requiredType = parameter . ParameterType ;
232243 this . name = parameter . Name ;
233244 this . nameContent = new GUIContent ( this . name , this . name ) ;
234- if ( parameter . IsOptional ) this . rawValue = parameter . DefaultValue ;
245+ if ( parameter . IsOptional )
246+ this . rawValue = parameter . DefaultValue ;
235247 InitType ( ) ;
236248 }
237249
@@ -244,27 +256,11 @@ public MethodPropertyDrawer(Type type, string name, object defaultValue, bool al
244256 InitType ( ) ;
245257 }
246258
247- void ListAddItem ( object value = null ) {
248- var drawer = new MethodPropertyDrawer ( requiredType . GetElementType ( ) , "" , value , privateFields , obsolete ) ;
249- drawer . OnRequireRedraw += RequireRedraw ;
250- arrayContentDrawer . Add ( drawer ) ;
251- }
252-
253259 void InitType ( ) {
254260 Helper . InitPropertyTypeMapper ( ) ;
255- if ( Helper . IsInterface ( requiredType , typeof ( IList < > ) ) ) {
261+ if ( requiredType . IsArray ) {
256262 castableTypes . Add ( PropertyType . Array ) ;
257263 currentType = PropertyType . Array ;
258- arrayHandler . headerHeight = EditorGUIUtility . singleLineHeight ;
259- arrayHandler . elementHeight = EditorGUIUtility . singleLineHeight + 2 ;
260- arrayHandler . drawHeaderCallback = r => EditorGUI . LabelField ( r , name ) ;
261- arrayHandler . drawElementCallback = ( r , i , c , d ) => arrayContentDrawer [ i ] . Draw ( false , Helper . ScaleRect ( r , offsetHeight : - 2 ) ) ;
262- arrayHandler . onAddCallback = l => ListAddItem ( ) ;
263- arrayContentDrawer . Clear ( ) ;
264- var enumerable = rawValue as IEnumerable ;
265- if ( enumerable != null )
266- foreach ( object item in enumerable )
267- ListAddItem ( item ) ;
268264 return ;
269265 }
270266 if ( requiredType . IsByRef )
@@ -303,7 +299,13 @@ public void Draw() {
303299
304300 public void Draw ( bool readOnly , Rect ? rect = null ) {
305301 readOnly |= isInfoReadonly ;
306- var referenceModeBtn = ( ! allowReferenceMode && ( currentType == PropertyType . Unknown || currentType == PropertyType . Object || currentType == PropertyType . Array ) ) || allowReferenceMode || ( allowReferenceMode && optionalPrivateFields ) || castableTypes . Count > 1 ;
302+ var referenceModeBtn = ( ! allowReferenceMode && (
303+ currentType == PropertyType . Unknown ||
304+ currentType == PropertyType . Object ||
305+ currentType == PropertyType . Array )
306+ ) ||
307+ allowReferenceMode ||
308+ castableTypes . Count > 1 ;
307309 if ( ! rect . HasValue )
308310 EditorGUI . indentLevel -- ;
309311 EditorGUILayout . BeginHorizontal ( ) ;
@@ -384,14 +386,6 @@ void InitFieldTypes() {
384386 selectedFieldIndex = - 1 ;
385387 }
386388
387- void SetArray ( ) {
388- arrayContentDrawer . Clear ( ) ;
389- if ( requiredType . IsArray && rawValue != null ) {
390- foreach ( object item in ( Array ) rawValue )
391- arrayContentDrawer . Add ( new MethodPropertyDrawer ( requiredType . GetElementType ( ) , "" , item , privateFields , obsolete ) ) ;
392- }
393- }
394-
395389 object GetReferencedValue ( ) {
396390 object val = null ;
397391 return Helper . FetchValue ( selectedField as MemberInfo ?? selectedProperty , component , out val ) ? val : null ;
@@ -576,16 +570,6 @@ void DrawDirectField(bool readOnly, Rect? rect) {
576570 else
577571 value = Helper . ObjectField ( nameContent , value as UnityObject , requiredType , true , readOnly ) ;
578572 break ;
579- case PropertyType . Array :
580- if ( rect . HasValue ) {
581- arrayHandler . DoList ( rect . Value ) ;
582- break ;
583- }
584- EditorGUILayout . BeginVertical ( ) ;
585- if ( arrayShown = EditorGUILayout . Foldout ( arrayShown , nameContent ) )
586- arrayHandler . DoLayoutList ( ) ;
587- EditorGUILayout . EndVertical ( ) ;
588- break ;
589573 case PropertyType . String :
590574 if ( rect . HasValue )
591575 value = Helper . StringField ( rect . Value , nameContent , ( string ) value , readOnly ) ;
@@ -626,7 +610,7 @@ void DrawUnknownField(bool readOnly, object target, Rect? position = null) {
626610 else
627611 clicked = GUI . Button ( position . Value , "…" , EditorStyles . miniButton ) ;
628612 if ( clicked )
629- InspectorChildWindow . Open ( target , true , privateFields , obsolete , true , false ) ;
613+ InspectorChildWindow . Open ( target , true , privateFields , obsolete , true , false , this ) ;
630614 }
631615
632616 void ShowMenu ( Rect position ) {
0 commit comments