Dragable windows that resize when screen size changes

Just thought I would share this technique, as i found it worked for me.

I like the drag-able windows, but hated that the size has to be set in a variable, since
the GUI function loops. (if you size it in the GUI you have to give it a location, and tying that
to a mouse movement would be a pain)

I like to re-size windows if they don’t have allot of text,or the users have different screen sizes.

Here is how I did it.

I created my own SKIN. There are server defaults that Unity provides, just pick one. You can make it your own.
I created a copy of the WINDOW default (manually) by creating a custom style, call in MyWindows, and using the same settings.
I did this so I could create the Window look (ie header bar, etc)

then I created another custom style that is simply empty. called “clearwindow”

so now, I setup a rectangle in my variables like this

private var windowRect1 : Rect 	= Rect (0, 0, 2000,2000);

then when I want to create a window (say on a button click)

I use…

windowRect1 = GUI.Window(1, windowRect1, IntroWindow, GUIContent.none,"warClearWindows");	
				GUI.BringWindowToFront(1);

Then in the function IntroWindow I create a group to help control the area, and then a BOX, but using
the Custom Style “MyWindows”.

So now I can calculate the size and location of the window based on Screen size, or changes in screen size, and its still drag-able.

So now flexible sized windows that can be moved!

Thanks for sharing. Will make it useful for some people. :smile: