Hi, I’m new to custom inspectors so please be patient. Let’s say my code looks like this:
public class ExampleClass : MonoBehaviour
{
public UnityEvent myEvent;
}
[CustomEditor(typeof(ExampleClass))]
public class EventEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if (GUILayout.Button("Add event"))
{
...
}
}
}
So I have 1 UnityEvent and what I’m trying to do is add another one when I press a button in my custom inspector. I’ve been googling for hours now and I just can’t get it to work.
I’ve tried something like this:
[CustomEditor(typeof(ExampleClass))]
public class EventEditor : Editor
{
SerializedObject _example;
void OnEnable()
{
SerializedObject _example= new SerializedObject((ExampleClass)target);
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if (GUILayout.Button("Add event"))
{
SerializedProperty sprop = _example.FindProperty("myEvent");
EditorGUILayout.PropertyField(sprop);
_example.ApplyModifiedProperties();
}
}
}
…but no luck
Help!