- Home /
GUI, Inspector has no control for Arrays?
Well, the default inspector I see has a control for Arrays, when I have "public int myInt;", the inspector knows it is an integer, and when drawing the object inspector, it displays an int-field control to handle that variable.. however, if I was to have an array like Object[] or List, the inspector can determine that it is an array, and draw the appropriate inspector, much like for integers, floats, and enumerators; However..
I cannot for the life of me figure out the control they used to ~inspect~ the arrays; D=
Any in-sight on this? I've actually made my own.. but it doesn't look the same as the built-in one, and I don't want people at all confused, so I am hoping someone has some info on how to use the array inspector that's built in.. thank you!
I found this documentation on SerializedProperties, http://unity3d.com/support/documentation/ScriptReference/SerializedObject.html;
It does not appear to work like I was hoping for.. =[ So, I'm still uncertain here!
Answer by Molix · Jun 09, 2010 at 02:05 AM
EditorGUILayout.Foldout is a special toggle control that is the little arrow used in the array (and other group) controls. e.g.
bool expanded = false;
void OnInspectorGUI() { ... expanded = EditorGUILayout.Foldout( expanded, "My Array" ); if( expanded ) { // draw count and elements } }
Does this mean that the only way to do it is manually? (e.g. the inspector won't do this automatically? Even if it shows the object's fields correctly when not in an array?) Thanks for posting.
Answer by qJake · Jun 08, 2010 at 10:25 PM
If you combine EditorGUILayout.BeginToggleGroup(...) (and, subsequently, EndToggleGroup(...)) and an array of EditorGUILayout.ObjectField(...)'s (or whatever the type of the Array is), you should get the effect you're looking for.
Answer by steinbitglis · Feb 24, 2012 at 02:02 PM
If you want to do this like DrawDefaultInspector(), look at my answer to this question.
Your answer
Follow this Question
Related Questions
How to show an array of custom objects in Inspector? 2 Answers
array inspector reordering 8 Answers
How to know if something is selected in Hierarchy or in project. 5 Answers
[INSPECTOR ARRAY] Replace 'Element 0' by 'Map 0' with auto increase 0 Answers
Dynamic Target for Object field (and others) in Custom Inspector 0 Answers