Game Development Reference
In-Depth Information
GUI events and properties
To support events in the legacy GUI area, Unity added an entire event handler
specifically for GUI interactions. This class is aptly named the Event class.
Remember, this section refers to the legacy GUI Event classes,
which has nothing to do with the new UnityEvent system
introduced in the new Unity UI system. See Chapter 6 , Working with
the UI Source, for more details of the UnityEvent system.
These events center on user and device input, varying from:
Event types : Is it a key event, mouse event, and so on
Event values : Which key pressed, mouse button pressed, and so on
Event summary information : Modifier keys, mouse movement delta,
and so on
To access the events you simply need to query the Event.current property to get
the current Event state. (The Event state updates when there is a change, until then
you will get the last/previous state.)
The logon example earlier shows an example for using events, where we detect if
the user has pressed a key and if that key is the Enter key as shown in this script:
if ( Event.current.isKey &&
Event.current.keyCode == KeyCode.Return &&
GUI.GetNameOfFocusedControl() == "PasswordField")
{
CheckUserPasswordAndRegister();
}
Along with the events, the GUI class also provides some additional properties you
can query or set in the OnGUI method, namely:
enabled : Is the GUI enabled and displayed on the screen. Can it be used to
turn on or off controls that are to be drawn to the screen.
changed : This returns true if any controls' values have changed since the last
call of OnGUI .
color : This is the global color tint for the GUI layout.
contentColor : This is the global text color tint for the GUI.
 
Search WWH ::




Custom Search