0
\$\begingroup\$

I am working through the popwindow sample code provided in the documentation here. So far my code opens up an instance of PopupExample when user clicks on a sprite. But I am unable to understand how PopupExample's position and size is being determined. The line below from the sample code, is setting the activator rect of PopupExample to buttonRect. And buttonRect is initialized to default values, which should be x=0f; y=0f; width=0f; height=0f.

PopupWindow.Show(buttonRect, popup);

When I run the code and click on the sprite, the popupwindow shows up on the upper-left corner of the IDE(screenshot below). I was expecting it show up somewhere within the scene itself. Why is it not contained within the scene? Also how can a widow with width and height initialized to 0f be visible at all?

enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ Does that window script extend from EditorWindow by any chance? That's designed to help programmers create UI for designers so they can tweak certain things, It wouldn't be compiled when you actually build the game. \$\endgroup\$ Commented Jun 14, 2018 at 15:32

1 Answer 1

0
\$\begingroup\$

Essentially you are using the wrong kind of Window script.

The EditorWindow is an internal UI Window used as an empty template provided by Unity so programmers can design interfaces for designers and artists to tweak settings in the inspector (Much like you do with GameObjects and their components but for custom components) the EditorWindow itself is all over Unity.

The console Window is an EditorWindow, as is, Hierarchy, Inspector Panel etc.

The reason you don't set the EditorWindow's x, y, wdith, height is because they are managed by Unity itself, you can resize, move, place the place panel where you want and Unity saves its settings.

What you need to do is click Create in the scene Hierarchy and then scroll down to Panel under UI and add it to the scene, this gives you an empty window, you can then add UI components to this panel, such as text, buttons, images etc by adding them as children of the panel you created.

That way whenever you want to hide the entire panel you can disable the Panel GameObject and re-enable whenever you want it shown it's children (images, buttons, text will disable with it since they are children of it)

If you are still confused I can provide further help.

\$\endgroup\$
1
  • \$\begingroup\$ thanks a bunch. That clarifies a lot. I will try the Panel today and post a new question if I have issues with it. \$\endgroup\$
    – sotn
    Commented Jun 14, 2018 at 17:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .