I would like to add a contextual menu at mouse position, when the user clicks on a MenuItem. I tried this (and many more) but can’t manage to do what I want. Action list is filled dynamicaly, thus I cannot declare several submenus to MenuItem.
To my knowledge there is no easy and reliable way to get OnGUI callbacks in the editor without creating an EditorWindow. There are things like SceneView.duringSceneGui and EditorApplication.hierarchyWindowItemOnGUI, but those won’t work unless the window in question is open in the editor. An ugly hack of a solution would be to create a temporary off-screen EditorWindow and leverage its OnGUI function to open the menu.
Or you could also create your own PopupWindow, that would probably work.
Also, I seem to have a hazy recollection that GenericMenu.ShowAsContext can not be called outside of mouse click events, but that GenericMenu.DropDown can. Not sure if GenericMenu.DropDown still requires OnGUI or works when called from a menu item though.