@@ -19,6 +19,7 @@ public class MethodPropertyDrawer: IReflectorDrawer, IDisposable {
1919 private object rawValue ;
2020 private bool referenceMode ;
2121 private int grabValueMode ;
22+ private ArrayConstructorDrawer arrayConstructorDrawer ;
2223
2324 private UnityObject component ;
2425 private readonly List < ComponentFields > fields ;
@@ -34,6 +35,7 @@ public class MethodPropertyDrawer: IReflectorDrawer, IDisposable {
3435 private bool obsolete = true ;
3536 private bool masked ;
3637 private bool isInfoReadonly ;
38+ private bool hasGetValue ;
3739 private readonly bool isStatic ;
3840 private readonly bool isPrivate ;
3941 public event Action OnRequireRedraw ;
@@ -149,6 +151,7 @@ public object Value {
149151 }
150152 set {
151153 rawValue = value ;
154+ hasGetValue = true ;
152155 Changed = false ;
153156 }
154157 }
@@ -182,6 +185,7 @@ public MethodPropertyDrawer(FieldInfo field, object target, bool allowPrivate, b
182185 name = field . GetMemberName ( true ) ;
183186 nameContent = new GUIContent ( name , field . GetMemberName ( ) ) ;
184187 rawValue = field . GetValue ( target ) ;
188+ hasGetValue = true ;
185189 this . target = target ;
186190 isStatic = field . IsStatic ;
187191 isPrivate = field . IsPrivate ;
@@ -202,6 +206,7 @@ public MethodPropertyDrawer(PropertyInfo property, object target, bool allowPriv
202206 name = property . GetMemberName ( true ) ;
203207 nameContent = new GUIContent ( name , property . GetMemberName ( ) ) ;
204208 }
209+ hasGetValue = initValue ;
205210 if ( initValue ) rawValue = property . GetValue ( target , indexParams ) ;
206211 this . target = target ;
207212 var getMethod = property . GetGetMethod ( ) ;
@@ -215,6 +220,7 @@ public MethodPropertyDrawer(ParameterInfo parameter, bool allowPrivate, bool all
215220 requiredType = parameter . ParameterType ;
216221 name = parameter . Name ;
217222 nameContent = new GUIContent ( name , name ) ;
223+ hasGetValue = true ;
218224 if ( parameter . HasDefaultValue )
219225 rawValue = parameter . DefaultValue ;
220226 InitType ( ) ;
@@ -225,6 +231,7 @@ public MethodPropertyDrawer(Type type, string name, object defaultValue, bool al
225231 requiredType = type ;
226232 this . name = name ;
227233 nameContent = new GUIContent ( name , name ) ;
234+ hasGetValue = true ;
228235 rawValue = defaultValue ;
229236 InitType ( ) ;
230237 }
@@ -270,6 +277,22 @@ private void InitType() {
270277 public void Draw ( bool readOnly , Rect ? rect = null ) {
271278 if ( target . IsInvalid ( ) && memberInfo . IsInstanceMember ( ) )
272279 return ;
280+ if ( requiredType != null && requiredType . ContainsGenericParameters ) {
281+ Rect sRect = rect . HasValue ? rect . Value : EditorGUILayout . GetControlRect ( true , EditorGUIUtility . singleLineHeight , GUI . skin . button ) ;
282+ sRect = EditorGUI . PrefixLabel ( sRect , nameContent ) ;
283+ GUI . Label ( sRect , "Unresolved Generic Type" ) ;
284+ return ;
285+ }
286+ if ( ! hasGetValue ) {
287+ const string labelText = "Fetch Value..." ;
288+ Rect sRect = rect . HasValue ? rect . Value : EditorGUILayout . GetControlRect ( true , EditorGUIUtility . singleLineHeight , GUI . skin . button ) ;
289+ sRect = EditorGUI . PrefixLabel ( sRect , nameContent ) ;
290+ if ( GUI . Button ( sRect , labelText , GUI . skin . button ) ) {
291+ hasGetValue = true ;
292+ rawValue = ( memberInfo as PropertyInfo ) . GetValue ( target ) ;
293+ }
294+ return ;
295+ }
273296 readOnly |= isInfoReadonly ;
274297 var referenceModeBtn = ( ! allowReferenceMode && (
275298 currentType == PropertyType . Unknown ||
@@ -283,6 +306,8 @@ public void Draw(bool readOnly, Rect? rect = null) {
283306 Rect sRect = referenceModeBtn ? Helper . ScaleRect ( rect . Value , offsetWidth : - EditorGUIUtility . singleLineHeight ) : rect . Value ;
284307 if ( referenceMode || grabValueMode == 1 )
285308 DrawReferencedField ( sRect ) ;
309+ else if ( grabValueMode == 4 )
310+ DrawArrayCtorField ( sRect ) ;
286311 else if ( grabValueMode == 3 )
287312 DrawRequestReferenceField ( sRect ) ;
288313 else
@@ -297,6 +322,8 @@ public void Draw(bool readOnly, Rect? rect = null) {
297322 EditorGUILayout . LabelField ( GUIContent . none , GUILayout . Width ( EditorGUIUtility . singleLineHeight ) ) ;
298323 if ( referenceMode || grabValueMode == 1 )
299324 DrawReferencedField ( null ) ;
325+ else if ( grabValueMode == 4 )
326+ DrawArrayCtorField ( null ) ;
300327 else if ( grabValueMode == 3 )
301328 DrawRequestReferenceField ( null ) ;
302329 else
@@ -324,11 +351,11 @@ public void Draw(bool readOnly, Rect? rect = null) {
324351 var sb = new System . Text . StringBuilder ( ) ;
325352 var exception = getException ;
326353 do {
327- if ( ! exceptions . Add ( exception ) ) break ;
328- if ( sb . Length > 0 ) sb . AppendLine ( ) ;
354+ if ( ! exceptions . Add ( exception ) ) break ;
355+ if ( sb . Length > 0 ) sb . AppendLine ( ) ;
329356 sb . Append ( '>' , exceptions . Count - 1 ) ;
330357 sb . Append ( $ "{ exception . GetType ( ) . Name } : { exception . Message } ") ;
331- } while ( ( exception = exception . InnerException ) != null ) ;
358+ } while ( ( exception = exception . InnerException ) != null ) ;
332359 EditorGUILayout . HelpBox ( sb . ToString ( ) , MessageType . Error ) ;
333360 }
334361 }
@@ -344,6 +371,7 @@ public bool UpdateIfChanged() {
344371 }
345372
346373 public bool UpdateValue ( ) {
374+ hasGetValue = true ;
347375 if ( memberInfo . FetchValue ( target , out var value , indexParams ) ) {
348376 rawValue = value ;
349377 GetException = null ;
@@ -559,7 +587,7 @@ private void DrawDirectField(bool readOnly, Rect? rect) {
559587 value = EditorGUILayout . Vector4Field ( name , Helper . GetOrDefault < Vector4 > ( value ) ) ;
560588 break ;
561589 case PropertyType . Quaterion :
562- if ( masked ) {
590+ if ( masked ) {
563591 if ( rect . HasValue )
564592 value = Helper . EulerField ( rect . Value , name , Helper . GetOrDefault ( value , Quaternion . identity ) ) ;
565593 else
@@ -619,8 +647,29 @@ private void DrawDirectField(bool readOnly, Rect? rect) {
619647 else
620648 value = Helper . StringField ( nameContent , ( string ) value , readOnly ) ;
621649 break ;
650+ case PropertyType . Type :
651+ EditorGUI . BeginDisabledGroup ( readOnly ) ;
652+ var rect2 = rect . HasValue ? rect . Value : EditorGUILayout . GetControlRect ( true , EditorGUIUtility . singleLineHeight , EditorStyles . textField ) ;
653+ rect2 = EditorGUI . PrefixLabel ( rect2 , nameContent ) ;
654+ Rect buttonRect ;
655+ if ( rect . HasValue ) {
656+ buttonRect = Helper . ScaleRect ( rect2 , 1 , 0 , 0 , 1 , - 34 , 0 , 32 ) ;
657+ rect2 = Helper . ScaleRect ( rect2 , 0 , 0 , 1 , 1 , 0 , 0 , - 36 ) ;
658+ } else
659+ buttonRect = Rect . zero ;
660+ if ( GUI . Button ( rect2 , value is Type t ? $ "T: { t . FullName } " : "<Null>" , EditorStyles . textField ) && ! readOnly ) {
661+ var typeMatcherPopup = new TypeMatcherPopup ( null ) ;
662+ typeMatcherPopup . OnSelected += type => rawValue = type ;
663+ PopupWindow . Show ( rect2 , typeMatcherPopup ) ;
664+ }
665+ EditorGUI . EndDisabledGroup ( ) ;
666+ if ( rect . HasValue )
667+ DrawUnknownField ( readOnly , value , buttonRect ) ;
668+ else
669+ DrawUnknownField ( readOnly , value ) ;
670+ break ;
622671 default :
623- var stringValue = value != null ? value . ToString ( ) : "Null" ;
672+ var stringValue = value != null ? value . ToString ( ) : "< Null> " ;
624673 if ( rect . HasValue ) {
625674 Helper . StringField ( Helper . ScaleRect ( rect . Value , 0 , 0 , 1 , 1 , 0 , 0 , - 36 ) , nameContent , stringValue , true ) ;
626675 DrawUnknownField ( readOnly , value , Helper . ScaleRect ( rect . Value , 1 , 0 , 0 , 1 , - 34 , 0 , 32 ) ) ;
@@ -656,6 +705,26 @@ private void DrawUnknownField(bool readOnly, object target, Rect? position = nul
656705 InspectorChildWindow . Open ( target , true , privateFields , obsolete , true , false , this ) ;
657706 }
658707
708+ private void DrawArrayCtorField ( Rect ? position = null ) {
709+ if ( ! position . HasValue ) EditorGUILayout . BeginVertical ( ) ;
710+ if ( requiredType . IsGenericType ) {
711+ if ( position . HasValue )
712+ EditorGUI . HelpBox ( position . Value , "Type is not resolved." , MessageType . Error ) ;
713+ else
714+ EditorGUILayout . HelpBox ( "Type is not resolved." , MessageType . Error ) ;
715+ return ;
716+ }
717+ if ( arrayConstructorDrawer == null ) arrayConstructorDrawer = new ArrayConstructorDrawer ( requiredType . GetElementType ( ) ) ;
718+ arrayConstructorDrawer . Draw ( ) ;
719+ if ( position . HasValue ? GUI . Button ( position . Value , "Create Array" ) : GUILayout . Button ( "Create Array" ) ) {
720+ Value = arrayConstructorDrawer . ToArray ( ) ;
721+ arrayConstructorDrawer . Dispose ( ) ;
722+ arrayConstructorDrawer = null ;
723+ grabValueMode = 0 ;
724+ }
725+ if ( ! position . HasValue ) EditorGUILayout . EndVertical ( ) ;
726+ }
727+
659728 private void ShowMenu ( Rect position ) {
660729 var menu = new GenericMenu ( ) ;
661730 if ( castableTypes . Count > 1 )
@@ -669,9 +738,14 @@ private void ShowMenu(Rect position) {
669738 if ( ! allowReferenceMode )
670739 menu . AddItem ( new GUIContent ( "Mode/By Value" ) , grabValueMode == 0 , GrabValueMode , 0 ) ;
671740 menu . AddItem ( new GUIContent ( "Mode/From Component" ) , grabValueMode == 1 , GrabValueMode , 1 ) ;
672- if ( currentType == PropertyType . Unknown ) {
673- menu . AddItem ( new GUIContent ( "Mode/Construct" ) , grabValueMode == 2 , GrabValueMode , 2 ) ;
674- menu . AddItem ( new GUIContent ( "Mode/From Opened Inspectors" ) , grabValueMode == 3 , GrabValueMode , 3 ) ;
741+ switch ( currentType ) {
742+ case PropertyType . Array :
743+ menu . AddItem ( new GUIContent ( "Mode/Construct" ) , grabValueMode == 4 , GrabValueMode , 4 ) ;
744+ break ;
745+ case PropertyType . Unknown :
746+ menu . AddItem ( new GUIContent ( "Mode/Construct" ) , grabValueMode == 2 , GrabValueMode , 2 ) ;
747+ menu . AddItem ( new GUIContent ( "Mode/From Opened Inspectors" ) , grabValueMode == 3 , GrabValueMode , 3 ) ;
748+ break ;
675749 }
676750 }
677751 if ( currentType == PropertyType . Enum )
0 commit comments