- Home /
List of CustomEditor inside CustomEditor
Hello everyone
I've been working in a project that has some data that need to be properly shown in the editor, but still didn't figured out how to show in a CustomEditor a list of ojects that show themselves with their own customEditors.
This is what I would love to have (but apparently, doesn't exist)
[Serializable]
public class ClassA : ScriptableObject
{
[SerializeField]
public GameObject Target = null;
[SerializeField]
public string Name = string.Empty;
}
[CustomEditor(ClassA)]
public class ClassAEditor : Editor
{
public override void OnInspectorGUI ()
{
EditorGUILayout.LabelField("CLASS A EDITOR");
base.OnInspectorGUI();
}
}
public class ListOfClassA : MonoBehaviour
{
public List<ClassA> classes = new List<ClassA>();
}
[CustomEditor(ListOfClassA)]
public class ListOfClassAEditor : Editor
{
private ListOfClassA list;
private SerializedObject targetObject;
private SerializedProperty listProperty;
void OnEnable()
{
list = (ClassA)target;
targetObject = new SerializedObject(list);
listProperty = targetObject.FindProperty("classes"); // Find the List in our script and create a refrence of it
}
private bool listVisibility = true;
public override void OnInspectorGUI ()
{
targetObject.Update();
//Or add a new item to the List<> with a button
if(GUILayout.Button("Add ITEM"))
{
list.classes.Add(CreateInstance<ClassA>());
}
EditorGUI.indentLevel++;
for (int i = 0; i < listProperty.arraySize; i++)
{
SerializedProperty itemProperty = listProperty.GetArrayElementAtIndex(i);
EditorGUILayout.PropertyField(itemProperty); // WHY IS THIS NOT SHOWING CLASSA CUSTOM EDITOR????
}
EditorGUI.indentLevel--;
targetObject.ApplyModifiedProperties();
}
}
So what I would like is a way to call ClassA CustomEditor from ListOfClassA CustomEditor so the code is more spread.
This is because ClassA for me is the base class for a HUGE structure, including all posibilites of properties and fields is just not a way to do it.
Answer by BehindTheCode · Aug 27, 2014 at 08:47 AM
For anyone interested, here there is a tutorial that explain what I need step by step and pretty comprehensible.
Your answer
Follow this Question
Related Questions
Initialising List array for use in a custom Editor 1 Answer
Multiple Cars not working 1 Answer
Custom Editor: Objectfield clears on play 2 Answers
Prefabs aren't saving with Undo.RecordObject 4 Answers
Distribute terrain in zones 3 Answers