Recreating the Onclick() event function dropdown menu

Hi,
I’m looking to make something identical to the onclick event dropdown with a list of all the functions attached to a certain gameObject. I’m having trouble actually writing the GUI script for this and displaying a dropdown of all the functions. This is my script.

class test {   
[HideInInspector]
    public List<MethodInfo> methods = new List<MethodInfo>();
    private BindingFlags flag = BindingFlags.Public;

    private void OnEnable()
    {
        var mb = effected.GetComponent<MonoBehaviour>().GetType().GetMethods(flag);
        methods.AddRange(mb);
    }
}

GUI script:

[CustomEditor(typeof(PressableButton))]
public class MethodListDrawer : Editor
{
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        PressableButton scr = (PressableButton)target;

        GUIContent label = new GUIContent("MyArray");
        EditorGUILayout.Popup(scr.selected, scr.methods.ToArray());
    }

Thanks.

For your inspiration, here is the for the UnityEventDrawer for reference

1 Like

thanks that helped, now I am able to create a dropdown us EditorGUILayout.popup() but now how do I give a call to the function? So in class A I have function 1, so in class B how do I call function1 on the instance of class A?