Game Development Reference
In-Depth Information
Objective Complete - Mini Debriefing
We just created our inventory page that we'll be able to view by clicking the
INVENTORY
tab. In the
Start()
funcion, we set up our
item
object if there is more than one item
assigned in
a_items
. Next, we added
ItemWindow()
line in the
DoMyWindow()
funcion,
and created
ItemWindow()
funcion to control our item page. In this funcion, we created a
scroll view by using
GUI.BeginScrollView()
and
GUI.EndScrollView()
, and created
a scrollable area that contains all the items. We also used
GUI.SelectionGrid
to create
our items list from which the player can select any item. Then, we get the current toolip
from
GUIContent
and check to see whether there is any informaion or not. Next we check
GUI.tooltip
for any stored string; if nothing is stored here we assign the current
tooltip
from our selected items to
GUI.tooltip
, which will show the result that if we roll over
each item the current informaion will change to the rollover item. On the other hand, if
we rollover from our items list, the result of the informaion will show the selected item
informaion. Next, we get the
Label
style height from the current
GUI.tooltip
. Then, we
created another scroll view to show this
tooltip
informaion in the box area.
Classified Intel
In this step, we were using
GUI.SelectionGrid
to create the list of the items. By using
GUI.SelectionGrid
, we were able to create a list of butons that have a ixed height and
space in one line of code, which was very convenient. We can see more details on how to
use
GUI.SelectionGrid
at this URL:
http://unity3d.com/support/documentation/ScriptReference/GUI.
SelectionGrid.html
.
We also used the
GUI.tooltip
parameter to be able to show our items' informaion when
the player rolls over each item and show the selected item informaion if the player rolls out.
So, how does
GUI.tooltip
work? Basically,
GUI.tooltip
will return the string from each
buton that contains a
tooltip
string when the player rolls over it. However, if the player
rolls out or that buton doesn't have any
tooltip
store, this parameter will automaically
return a blank string, similar to the following code that we used:
if (GUI.tooltip != "") {
//Get height from this style
var f_height : float = style.CalcHeight(GUIContent(GUI.tooltip),
330.0);
scrollPosition2 = GUI.BeginScrollView (new Rect (257, 343, 320,
75), scrollPosition2, new Rect (0, 0, 280, f_height));
GUI.Label(new Rect (0, 0, 280, f_height), GUI.tooltip);
} else {
//Get height from this style
f_height = style.CalcHeight(GUIContent(s_info), 330.0);