Mastering Unity 2017 Game Development with C#(Second Edition)
上QQ阅读APP看书,第一时间看更新

Level building - Organization and structure

Let's start the level construction process. There are many ways to begin here, but it's a good idea from the outset to develop with a clean workflow in mind. By clean, I mean an organized, structured, and easy-to-maintain workflow, one that remains maintainable for projects of many scales. First, delete any and all objects in the new scene, and then create a single empty GameObject named root by navigating to GameObject | Create Empty from the application menu. This object will be the topmost object in the hierarchy, from which everything else will be a child directly or indirectly:

Creating a root object for the scene

Next, create a new child object named env, which will contain all environment pieces. Ensure that both the root and env objects are positioned at the world origin at (0,0,0). I typically position the world floor at 0 on the y axis, making this the lowest point in the world. It is, of course, possible for objects to fall below this point, but by convention, we can set all negative Y values as a kill zone. In this game, camera paths are predetermined; however, we need not concern ourselves with this, but it's worth considering for free-roaming cameras:

Structuring the scene hierarchy

Now, drag and drop the modular pieces from the Project panel into the scene, building a maze-like interior. You can align mesh pieces together exactly at the edge vertices using Vertex Snapping. To access Vertex Snapping, switch to the Translate tool with T on the keyboard, hold down the V key, and then click and drag your mouse from the source mesh to the destination, hovering your cursor over the vertices. When you do this, one mesh snaps to the other automatically. By repeating this process for each mesh module, you can easily align all mesh pieces together. It is good practice to first plan your level layout using a digital drawing application; Photoshop, Paint, or Graphic Design software:

Snapping mesh modules together
When building levels, start by dragging and dropping a single copy of every mesh into the level to establish a palette of meshes. Then, maximize the Scene viewport with Shift + spacebar, and continue building the level by duplicating the extant pieces as needed in fullscreen. This saves you from jumping between a maximized and normal view, between the scene and Project panel, to access your meshes.

After arranging meshes, you'll get an initial level arrangement that should be tested for any obvious problems (such as holes) using a first person controller--or a third person controller, if your game is not first person. Remember to deactivate Lighting Previews for the Scene tab for your initial level; this makes it easier to see and position mesh pieces. You can do this using the Scene toolbar. First, focus on establishing the overall scene size, general layout and placement of objects, and the start and end locations. The rest of the scene can be developed functionally and aesthetically alongside these ingredients:

Building an initial level