I am trying to streamline the EditorGUI process by creating some generic functions that I use often in most of my Editor GUI classes. I’m sort of stuck on this one, though: I am trying to create a generic List<> GUI. I know how to do it when I know the type of the List, but I’m trying to make this as generic as possible.
Here’s an example of the GUI when typed strictly to strings:
bool StringListGUI (bool open, string s, List<string> list){
bool b = EditorGUILayout.Foldout(open, s);
if(b){
EditorGUI.indentLevel++;
for(int i = 0; i < list.Count; i++){
EditorGUILayout.BeginHorizontal();
list[i] = EditorGUILayout.TextField(list[i]);
if(RemoveButton()){
list.RemoveAt(i);
i--;
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.BeginHorizontal();
string n = EditorGUILayout.TextField("");
if(n != "") list.Add(n);
EditorGUILayout.EndHorizontal();
EditorGUI.indentLevel--;
}
return b;
}
bool RemoveButton (){
if(GUILayout.Button("X", GUILayout.Width(30))) return true;
return false;
}
I would like to convert that into something which could be sent a List of any type. I’m alright with having a button to create a new object rather than the dynamic field I have in there currently. Any help is greatly appreciated!