• No results found

1: Creating a Unity Project

If you have not downloaded and installed Unity at this point, please do so now. Remember the standard Unity license is free and available at http:// www.unity3d.com. Just go to the Download section. There are some very nice features in Unity Pro (real-time shadows, deferred rendering, occlusion culling), but to learn Unity, there is plenty that can be done with the standard (and free) Unity.

To set up a new Unity project and to set up Unity to effectively allow for the management of projects, do the following.

Step 1: After installing Unity, when run, Unity will present a Unity-Project

Wizard window (Figure 5.1). This Wizard has two tabs: the Open Project and Create New Project.

Tips and Tricks

If you've already been using Unity, there will be a slew of projects listed in the Open Project tab. In fact, if you've already been using Unity, the wizard may not be presented at all. Unity automatically defaults and opens to the last opened project and thus skips the Project Wizard. I'm not a big fan of this method because it opens up a lot of possible mistakes of saving files to the wrong project. Luckily Unity has a setting (Edit>Preferences) called Show Project Wizard at Startup. Activate this so that when Unity is launched you always know that you are working in the correct project.

Step 2: Select the Create New Project tab.

Step 3: Click the Browse… button. Choose a location to save the Project

file. Create a new folder (Unity requires that the location of a new project be within an empty folder). In our case, it's easiest to find where you have your Incursion–Maya folder and (not within that folder but) at the same place create a folder named Incursion-Unity. Click Select Folder.

Why?

In the development of a game, there will be a lot of assets created and manipulated. If you've been doing 3D production for a while, you know how easily you can wind up in a mess if you don't keep a good eye on where you're storing your textures. In a game there not only are models and textures but a slew of other assets. By keeping the Maya file and the Unity projects in close proximity to each other it's not only easier to get assets from one place to another, but it keeps all the relevant data near.

Step 4: Back in the Create New Project tab, look in the “Import the

following packages:” section and choose “Character Controller. unityPackage”. Click Create.

Why?

There are a huge number of packages made available in this tab. Packages are just what they sound like: they are a little parcel of assets that include information on how these assets may (or may not) be tied together. Packages are a great way of moving certain types of assets (especially objects that have scripts draped on them) from project to project. Beginning Unity users often simply click all the packages. “I might need them sometime,” they say. And this could be true, they might be needed sometime, but until they are used, there is a tremendous performance price that is paid. Whenever a new script is made or changed, Unity recompiles all the scripts that are within the Assets folder. So if there are 50 or 100 scripts that were imported as part of these other packages that aren't used, Unity will have to take a look at them every time script editor is touched. Popping in and out of the script editor is a very common occurrence, and these slow compile times can really start to add up. Additionally, by keeping the project clean you ensure that you don't have some rogue script floating around your project that is affecting your project in ways you don't know about. Having said all that, we do know that we will be using the Character Controllers that come shipped with Unity (custom controllers can be built, but the included ones are sophisticated and powerful so we will restrain ourselves from reinventing the wheel and roll with the ones provided). So, now is a perfect time to include them.

If later we decide that we need the contents of other packages (which we will), we can always import them at a later time (which we also will do in the process of the tutorials).

About the New Project File

So what's happening now? Unity will chug along for a minute before presenting the Unity assembly interface. What Unity is doing is unpackaging the packages you've selected, as well as a few other packages of data, and putting them in some folders it will create on the hard drive. In the OS, look at the newly created Incursion–Unity folder, and find that it contains three folders: Assets, Library, and Temp. Generally, don't mess with the Library or Temp folders. The Assets folder though is where we will be doing much of our work.

Importing Items Paradigm

Don't actually import anything right this minute, because it's important to understand how we will interact with this new project file. The way to import assets into Unity is to (in the OS, not in Unity) find the Assets folder within the project folder. Then, using the OS, just drag the things Unity should access into the Assets folder. When a new model, texture, sound, or movie is placed there, Unity recognizes something new and acts on it—it attempts to understand the file and always attempts to import it. What this means is the

Assets folder should be treated with a bit of reverence, and not filled with garbage or files that won't be part of the game.

I've seen developers and students just throw their entire Maya project folder inside of this Assets folder. This is really a poor work flow as it forces Unity to analyze all the files (including all the raw texture construction files, swatches, incremental saves, etc.) and indeed to then chug away to convert all that stuff into forms Unity likes to work with. There really isn't a “please stop importing” button or a “ignore this stuff” option, so it becomes important that only the assets that are going to be used in the game end up in that Assets folder. Otherwise, there will be much waiting done as Unity chews on mounds of stuff that will never be used. Exactly which items to actually place in the Assets folder is actually a little trickier than it might sound. Some developers like placing their Maya file (.mb or .ma) there and then sorting through their sourceimages folder to pull out the textures they know they finally used in their project and including those in the Assets folder. I'm not a fan of this approach because it quickly becomes an unmanageable collection of files if there are multiple Maya files and keeping track of what textures are used where can be a chore.

Instead (and much more on this later), I prefer to export my files manually from Maya as a .fbx file and simply have that file embed the media it uses for the material creation. A streamlined collection of files into the Assets folder means a streamlined import process and a much more streamlined production cycle.

Deleting or Rearranging Items

While placing assets into the Unity project happens in the OS, deleting files from the project shouldn't be done in this way. When assets are dropped into the Assets folder, and Unity imports them, it creates a series of metadata files that help Unity keep track of where files are at and how they are tied to other files. The problem is that if files are deleted or moved around in the OS, the metadata doesn't go with it—or update to represent these changes. This can really mess Unity up as it loses track of where assets are.

Instead, whenever an already imported asset needs to be deleted or

reorganized, do it within Unity. This will happen within the Inspector window and we will look at how to do this in the tutorials to come. However, just keep in mind, from the project's inception, to bring in assets to be used in the game outside of Unity (in the OS), but once the assets are in Unity do all organizing and deletion within Unity—it will save much frustration. The details of Unity's import process will be covered in the coming pages.

Unity Interface

Figure 5.2 shows the Unity interface and what the parts of the interface are. We aren't going to spend a huge amount of time picking through this since, by this time, I'm sure you're anxious to get into it, but a quick overview will help in understanding how Unity “thinks.”

Warnings and Pitfalls

I know I just said it, but it bears repeating. Reorganize or delete the asset files only within Unity. Do not do so in the OS's file browser.

Toolbar

Across the top of the interface are some navigation and organizational tools. The first four tools are navigation tools. However, if these are used to navigate, a monumental amount of time is lost. If you're familiar with Maya's camera navigation tools, this will be an easy transition. Alt-left-mouse-button-drag orbits (or spins) the camera, Alt-middle-mouse-button-drag tracks (or slides up and down or back and forth) the camera, and Alt-right-mouse-button-drag dollys (or moves closer or further) the camera. Stay away from the interface navigation buttons. Use the keyboard/mouse shortcuts to move the camera about in the Scene view.

On a side note, to make Unity further like Maya, W activates the Move tool, E activates the Rotate tool, and R activates the Scale.

Next in line are the Pivot/Center and Local/Global toggle buttons. These have to do with where Unity places the handles for a selected object. They allow an object to be rotated around a pivot point that has been defined in Maya, or around the geometric center, and choose to move an object relative to its local orientation or relative to its local rotation. More on these later.

The VCR-looking buttons are about moving from the authoring environment to the game environment. Pressing the Play button plays the game. Pressing it again stops the game and returns to the authoring environment. The Pause button pauses the game play, which allows any physics simulations to stop or for the developer to take a close look at what's happening. The last button of the batch is the Step button, which allows for movement through the game or simulation one frame at a time. On the far right are two drop-down menus that allow for hiding (or making visible) various layers. Or choose various preset layouts. Objects can be assigned to layers. The layers can become very powerful because a layer can be hidden within the Scene view, and certain cameras can be told to see only certain layers (and this can be used with things like Raycasting). The Layout tab can be very handy if you are the kind of software user who tends to set up custom layouts for various tasks.

Scene

The Scene area is where the game is actually constructed. In this window objects can be placed or manipulated in space. This is most like Maya's View panels and even has that handy Scene Gizmo (in the top right corner), which helps understand where the editor camera is in global space and allows for quick movement to the various Top, Bottom, Right, and Left othrographic views. Note that there are several buttons at the top of the Scene area including the ability to show how the scene is presented. The scene can be shown as Wireframe, with Alpha, with or without Lights, Grid, and/or sound.

The other thing that is important to notice about the Scene area is that it's hiding the Game area.

Game

The Game view is actually what the game will look like. When you Play the game (Play with a capital P meaning you press the Play button), the Game window will come to the foreground where you actually see what happens in the game. This actually seems to me to be a really unintuitive way to work. Having either the Scene or the Game view visible can sometimes cause real problems when trying to understand what is happening in the game or when troubleshooting. If you have a big enough monitor to support it, you will find it worth your while to rearrange the default workspace to be able to see both the Scene and Game at the same time.

Tips and Tricks

To rearrange your workspace within Unity, just click and drag any of the tabs where the name of the area appears. So Game tab can be grabbed and remounted below the Scene area, or move the Hierarchy and Project views to your second monitor. It's really an important update to Unity 3, and makes Unity a much more configurable tool. Figure 5.3 shows how I have my workspace set up with my dual monitor setup.

Inspector Panel

This does exactly what it sounds like—it allows assets to be inspected. If an asset is selected in any view or panel (Scene, Hierarchy, or Project), the attributes of that object will be visible in the Inspector panel (think the

Figure 5.3 The WatkinsCustomLayout, made to utilize dual monitors by dragging areas of the interface around. Note the Console visible (an important tool not visible in the default layout).

Attribute Editor in Maya). Not only does this allow for the inspection of the asset, it also allows for changes to be made to the attributes of the object. Lots of attributes and connections can be seen here. Which scripts are attached to which GameObjects can be seen. Which texture is assigned to a mesh can be seen. Further, even important details like which scripts are talking to which other objects in the scene are laid out here.

Hierarchy Panel

This and the Project panel work in close concert. The Hierarchy panel shows what objects are in the scene. Here the organization of the objects can be changed (which objects are children of which) and, when the game is playing, can show what additional objects have been instantiated (which means “created during game play”). To get assets to the Hierarchy (and thus in the game), either put them there programmatically (via script) or drag them from the Project panel.

Notice that the Hierarchy panel has a Create drop-down menu that allows for the addition of all sorts of Unity-generated assets to the scene. This can also be done via the GameObject>Create Other drop- down menu.

Note too, that there is a search input field to find an asset that you know is in the scene but you can't quite find by perusing the list.

Project Panel

Think of this panel as the library or storage bin. This is where all the assets that are available for the game live until they are dropped into the Hierarchy (or pulled over via script). Remember that when assets are represented in the Hierarchy panel, they are in the game as well.

The Project panel is essentially the Assets folder. In the OS's file browser, when things are dragged into the Assets folder—and after they have been imported and understood by Unity—they will be presented in the Project panel. It is here that reorganizing and deleting of assets should be done (as discussed earlier in the chapter).

Notice that here too is a Create drop-down menu with a different collection of Unity-generated assets. Also, here new Folders for organizational purposes can (and should) be created to organize the assets into logical bins for easy access. Lastly, notice that here too is a search input field to find a particular asset if it's not immediately visible.

Using It All

So there's the crammed interface overview. The best way to learn an interface is to use it. The pieces and method to the madness begins to become clear. So let's

Tutorial 5.2: Exporting from Maya

Related documents