Game Development Reference
In-Depth Information
Classified intel
In this step, we used the GUI class to create our window, box, and buttons, but we can also
use a GUILayout class to create the same thing as we did with the GUI class. The only
difference between these two classes is that GUI will need to take a Rect object to specify
the size and position of the UI. On the other hand, GUILayout doesn't need to take the
Rect object. It will automatically adjust the size according to the source it has. Let's say,
we want to create a box that contains a text or image, GUILayout will automatically ad-
just the height and width to nicely fit your text or image. For the position, GUILayout
will automatically set the first position to the top-left corner of the screen, which is ( 0 , 0 ),
and it will continue to the right-hand side or down depending on the GUILayout object
that we already have on the screen. However, the downside is that we will not be able to
create a fixed position or size for the GUILayout class. Also, because the GUILayout
class will automatically calculate the position and size for us, this means that it will be
more expensive to use than the GUI class. However, the GUILayout class is very con-
venient and the UI editor in Unity is based on this class, we can use it to create the custom
editor script combined with the EditorGUILayout (we will learn about the custom edit-
or in a later project). Both of these classes are very powerful. We can use them in different
situations.
You can see more details of the GUI class at the following URL:
http://unity3d.com/support/documentation/ScriptReference/GUI.html
You can see the details of the GUILayout class at the following URL:
http://unity3d.com/support/documentation/ScriptReference/GUILayout.html
The GUI.DragWindow() function allows us to create a draggable window by specifying
the drag area on our window. You can visit the following URL to see the details:
http://unity3d.com/support/documentation/ScriptReference/GUI.DragWindow.html
This function takes one Rect parameter, which is the area that allows the user to drag the
window around. However, we didn't assign the Rect parameters to our
GUI.DragWindow() function, which means that we can drag the whole window in an
area.
Search WWH ::




Custom Search