Hello,
I’m having some trouble figuring out how to get Unity’s Inspector to draw lists within lists. For instance, if you have a list of foldouts containing values, how do you make it possible to draw a list under each entry? I’ve tried using a jagged array ([ ][ ]), wrapped class type, and List<variable[ ]>, I keep getting null reference errors that when I try to fix, I reach what seems like limits in the built in “serializedObject” method or some other medley of errors that brings me back to where I started. At this point I’m not sure what code to give you to explain what I’m doing, but I’ll try.
In the actual script is:
public TypeWrapper[] BlockBuildBool;
…and at the end of it:
public class TypeWrapper : MonoBehaviour {
public List<bool> buildTypes;
public void initiate() {
buildTypes = new List<bool>();
}
}
Then in the editor:
GUIContent blockLabel = new GUIContent("Block Types");
EditorList.Show (serializedObject.FindProperty("BlockNames"),serializedObject.FindProperty("BlockDensities"),serializedObject.FindProperty("BlockBool"),serializedObject.FindProperty("BlockBuildBool"),Script.BlockBuildBool,Script.BuildingNames.Length,blockLabel,EditorListOption.ParentList2);
… and the show function of editorlist class:
public static void Show (SerializedProperty list, SerializedProperty child, SerializedProperty child2, SerializedProperty child3, TypeWrapper[] child3Var, int limit, GUIContent label, EditorListOption options) {
bool
asPList2 = (options EditorListOption.ParentList2) != 0;
while (child.arraySize > list.arraySize) {
child.arraySize--;
}
while(child.arraySize < list.arraySize) {
child.arraySize++;
}
while (child2.arraySize > list.arraySize) {
child2.arraySize--;
}
while(child2.arraySize < list.arraySize) {
child2.arraySize++;
}
while (child3.arraySize > list.arraySize) {
child3.arraySize--;
}
while(child3.arraySize < list.arraySize) {
child3.arraySize++;
}
if(asPList2){
EditorGUILayout.PropertyField(list,label);
if(list.isExpanded){
EditorGUI.indentLevel++;
for(int i = 0;i < list.arraySize;i++){
GUIContent foldLabel = new GUIContent(list.GetArrayElementAtIndex(i).stringValue);
EditorGUILayout.BeginHorizontal();
child2.GetArrayElementAtIndex(i).boolValue = EditorGUILayout.Foldout(child2.GetArrayElementAtIndex(i).boolValue,foldLabel);
DeleteButton(list,child,child2,i);
EditorGUILayout.EndHorizontal();
if(child2.GetArrayElementAtIndex(i).boolValue){
EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i),nameLabel);
GUIContent densLabel = new GUIContent("Density:");
EditorGUILayout.IntSlider(child.GetArrayElementAtIndex(i),0,4,densLabel);
}
}
AddButton(list,child,child2);
EditorGUI.indentLevel--;
}
}
}
Assuming any items unrelated to child3, the intended nested list item, are properly declared and functioning, any suggestions on how to go about nesting a jagged array, wrapped type class or List<item[ ]>, so that each item in the parent list holds another list using the end level array?