Game Development Reference
In-Depth Information
This method is where you will add all your GUI code using the previous examples;
each control is positioned is based off the top-left position of the window when it is
displayed (same as the
Group
and
ScrollView
controls described earlier).
Additionally, you can specify any of the previous options for the window,
for example:
void DoMyWindow(int windowID)
{
GUI.Label(new Rect(25, 15, 100, 30), "Label");
// Make the window Draggable
GUI.DragWindow();
}
With your
Window
method in place, you just need to call the
GUI.Window
function
to open it along with the property to track the
Window's
location:
private Rect rctWindow1;
void OnGUI()
{
Rect rctWindow1;
rctWindow1 = GUI.Window(0,
rctWindow1,
DoMyWindow,
"Controls Window");
}
This calls
Window
control into view using:
• An ID for the window
• The
Rect
position for where
Window
will open
• The delegate method for the GUI contents of
Window
• A name/title for the window
If you want a modal window, then you would need to instantiate the window with
the
GUI.ModalWindow
function instead of the
Window
function:
rctWindow1 = GUI.ModalWindow(0, rctWindow1, DoMyWindow, "Modal
Controls Window");
If we take all the controls together (that we have created so far in this chapter),
it would create a
Window
view, as shown in the following screenshot:
For a complete end-to-end example, please see the code download
package, which has all this defined.