Game Development Reference
In-Depth Information
It's perhaps this logistical distinctiveness of GUIs that have historically made them an uneasy and
awkward fit in the feature-set of most 3D engines. Most engines have legacy features and editor
quirks for GUIs, which are the direct result of attempts over time by engine developers to rethink
and reinvent how GUI development could optimally work with the rest of the 3D development tools.
The hope of most game developers is to have a fully functional 2D GUI editor, complete with GUI
widgets and controls like those in popular GUI IDEs (integrated development environments), such
as the Qt framework, the Embarcadero C++Builder, or the .NET Framework. But this dream has still
not been realized in most engines, at the time of writing. This has made GUI development for games
a comparatively laborious and messy affair. One common solution in engines today is to simply
disregard support for any native GUI development. With this solution, GUI development is typically
delegated entirely to third-party tools, like Adobe Flash. From here, the engine offers support by
allowing a compiled Flash presentation to be embedded into and connected to the game through
add-ons and plug-ins like Autodesk Scaleform.
Unity, however, doesn't take the Scaleform approach natively. Instead, it makes an attempt to offer
native GUI development features. Until Unity 4.3, it offered these almost exclusively through the GUI
class. More information on this class can be found at https://docs.unity3d.com/Documentation/
Components/GUIScriptingGuide.html . However, this class became unpopular among many developers
for performance reasons. And many developers even abandoned the GUI class entirely, coding their
own custom GUI solutions from the ground upward, or else they used a range of third-party GUI
frameworks from the Unity Asset Store.
But since version 4.3, newer and easier possibilities beyond the GUI class have emerged through the
added 2D functionality and sprite features; and (as I write this) it is expected that there will be even
more GUI functionality and further developments in an upcoming Unity 4.6 release. This release is
not available to me at the time of writing this chapter, but it may be available to you when you are
reading this chapter.
In short, this chapter will explore GUI development almost entirely with the Unity 4.3 sprite
functionality, along with orthographic cameras (as explained in Chapter 6 when creating weapons).
It may be that upcoming GUI features—whatever they are—will make GUI development even easier
than the methods I've outlined here, but nonetheless, the methods here should remain valid and
applicable to later versions, too, and even apply in principle to other engines supporting similar 2D
sprite functionality.
Getting Started with GUIs
Since we'll be using the Unity 4.3 2D sprite functionality to create a GUI for CMOD, our first steps
in GUI development will resemble the first steps for creating weapons. Specifically, we'll create an
orthographic camera in the scene (to render graphics in 2D), with a Depth Only value set for the
Clear Flag field in the Object Inspector. And we'll also restrict camera rendering to only a designated
GUI layer using the Culling Mask field. More in-depth instructions on how to configure a dedicated
2D camera in Unity is covered in Chapter 6. You can also see the GUI camera setup and object
arrangement I've used in Figure 8-1 (and this project is included in the topic companion files
/Chapter08/ ).
 
Search WWH ::




Custom Search