Creating a popup list in scene view?

Hi,

I would like to show a popup when user clicks mouse button in editor scene view. This would be for an editor script and code is currently running in my editor window class which is an EditorWindow.

Example: user clicks some world coordinate in scene view (imagine it is a tile at 3,4 for example), I would then like to show a popup next to mouse cursor where I show items in that tile. When user clicks a choice (picks an item from the list) popup goes away.

I know I can do stuff in editor scene view by adding a delegate to SceneView.onSceneGUIDelegate and there is PopupWindow and EditorGUI.Popup, but I haven’t yet found any posts / articles about if it is possible to create such a popup in scene view using these.

Is this possible? Any help is appreciated - thanks!

I will finally answer this myself.

The solution that worked for me is to use Generic Menus:

GenericMenu menu = new GenericMenu();

I then populate it with stuff I need using menu.AddItem, and then give each element a callback delegate.

This way popup works pretty much without any work, when called with menu.ShowAsContext().

There are so many menu classes in Unity Editor that I couldn’t figure it out last time!

1 Like

GenericMenu is the simplest solution, but it’s also the most limited (has no scroll bars, no support for icons, etc).

For more advanced features I like to use UnityEditor.IMGUI.Controls.AdvancedDropdown which has tabbed headers, scrollbars and supports icons.

But because I also wanted to create a popup list in the SceneView with a completely custom look I used UnityEditor.PopupWindow to implement my own drawing for each row. The code is open source at: Nementic Selection Utility, see SelectionPopup in particular.

2 Likes

@Xarbrough_1

Thank you for this information - and I’ll probably check your utility at some point !