美文网首页成长、财富
Developing 2D Games with Unity b

Developing 2D Games with Unity b

作者: 小宁静致远 | 来源:发表于2019-04-14 20:27 被阅读5次

    Chapter 1
    Games and Game Engines

    In this introductory chapter, Jared Halpern talk a bit about game engines: what the are, and why they're userd. He also discussed a few game engines of historical significance, as well as introduce the high-level capabilities of Unity. If you want to get straigtht to making games, feel free to skim or skip this chapter and comd back to it later.

    Game Engines ---- What are they?
    Game engines are software development tools designed to reduce the cost, complexity, and time-to-market requied in the development of video games. These software tools create a layer of abstraction on top of the most common tasks in developping video games. The layers of abstraction are packaged together into tools designed to function as interoperable components that can be replaced outright or extended with additional thrid party components.

    Game engines provide tremendous efficiency benefits by reducing the depth of knoledge required to make games. The can be miniaml in their rpbuilt functionality or full-featured, allowing game developer to focus entirely on writing gameplay code. Game engines offer an incredible advantage over starting from scratch fro solo developers or teams who just want to focus on making the best game possible. When building the sample game in this book, you won't need to build complex mathematical libraries from the ground up or figure out how to render individual pixels on-screen, because the developers who created Unity have already done that work for you.

    Well-designed modern game engines do a good job of separting functionality internally. The gameplay code, which consists of code describing the player and inventory, is kept separate from the code that decompressed an .mp3 file and loads it into memory. Game play code will call on well-defined engine API interfaces to request things like "draw this sprite at this location" and so forth.

    The component-based architecture of a well-designed game engine allows for extensibility that ncourages adoption, because the development team is not locked into a predeterined set of engine capabilites. Theis extensibility is especially important if the game engine source code is not avaliable as open-source or is prohibitively expensive to license. The Unity game engine is purpose built to allow for third party plug-ins. It even goes so far as to provide an Asset Store containing plug-ins, accessible through the Unity Editor.

    Many game engines allow for cross-platform compilation as well, meaning that your game code is not constrained to a single platform. The engine does this by not making assumptions about the underlying computer architecture and letting the developer specify which platform they're using. If you wanted to release your game for console, desktop, and mobile, the game engine allows you to flip a few switches to set the build configuration to that platform.

    There are caveats to the miracles of cross-platform compilation though. Although cross-platform compilation is an amazing feature and testament to how far game technology has come, keep in mind that if you're building a ame from multiple platforms, you'll need to provide different imge sizes and allow fro the code reading in the controls to accept different kings of peripherals such as a keyboard. You might need to adjust the layout of your game on-screen as well as numerours other tasks. It can actually be a lot of work just to port a game from one platfrom to another, but you probably won't have to touch the game engine itself.

    Some game engines are so visually oriented htat they allow for the creation of games whthout writing a singel line of code. Unity has the ability ot customize user-interfaces that can be configured for use by other nonprogrammer members of the development team such as level designers, animators, art directors, and game designers.

    Ther are many different types of game engines, and there are no rules as to which functionality is absolutrely required to be condisered a game engine. The most poopular game engines contain some or all of the following functionality:

    . Gaphics rendering engines, supprting 2D or 3D graphices.
    . Physics engine that supports collision detection
    . Audio engine to load and play sourds and music files
    . Scripting supprot to implement gameplyay logic.
    . A world object model defining the contents and properties of the game world.
    . Animation handing to load animation frames and play them.
    . Networking code to allow for multiplyer, downladable content, and leaderboards.
    . Multithreading to allow game logic to execute simultaneously.
    . Memory management because no computer has unlimited memory.
    . Artifical intelligence for pathfinding and computer opponents.

    If you're not fully sold yet on on using a game engine, consider the following analogy.
    Say you want to build a house. To start iwth, this house will have a concrete foundation, a nice wood floor, sturdy walls, and a weather-treated wooden roof. The are two ways of going about building this house:

    The first way to build a house
    Excavate the ground using a hand shovel until you've dug sufficiently deep to plant the foundationi. Make concrete by heating limestone and clay at 2,640℉ in a liln, grind it, and mix in a bit of gypsum. Take the powdered concreate you've created, minx it with water, crushed stone or fine sand, and lay your foundation.

    At the same time you lay the foundation, you'll need stell rebars to strengthen the concrete. Gather the iron ore required to make stell rebar and smelt it in a blast furnace to amke ingots. Melt and hot-rool those ingots into sturdy reinfrrcement bars for the concrete foundation.

    After that, it's time to build the frame on which you'll hang your walls. Take your axe and strat chopping down trees. Felling a few hundred or so timber will be enough to supply the raw materials, but next you'll need to take each timber and mill them into lumber. When you're done, don't forget to treat the lumbers to it's weatherproof and doesn't rot or become infested with insects. Build out your joists and girders on which you'll lay the floot, and are you exhausted yet? We're just getting started!

    The second way to build a house
    Purchase bags of premixed concrte, steel rebar, treated lumber from a mill, a dozen boxes of paper-tape galvanized nails, and a pneumatic nail gun. Mix and pour your concrete to create your foundation, lay down the premade steel rebar, let the concrete set, then build out your floor with the treated lumber.

    About the first approach
    The first way of building a house requres tremendous amount of knowledge simply to create the materials needed to begin building a house. This approach requires that you know the precise ratio of raw materials needed and techniques to make concrete and steel. You'll need to know how to fell trees without ending up pinned underneath one, and you'll have to know the proper chemicals requred to treat the lumber, wich you've taken great pains to cut into hundreds of uniform beams. Even if you possessed all the knowledge requierd to build a house this way, it would still take you thousands of hours.

    This first approach is analogous to sitting down to write a video game without using a game engine. You must do everything from scratch: write the math libraties, graphices rendering code, collision detection algorithms, network code, asset loading libraries, audio player code, and much more. Even if you knew how to do all these things from the get-go, it would still take you a long time to write the game eninge code and debug it. If you aren't familiar with linear algebra, rendering techniques, and how to optimize culling algorithms, you should expect that it could take you years before you have enough of a game engine that you can actually start writing the game to along with it.

    About the second approach
    The second way of building a house assumes that you aren't starting entirely from scrath. It doesnt' requre that you know how to work a blast furnace, fell hundreds of timbers, or mill them to make lumber. The second way allows you to focus entirely on building the house instead of making the materials that you'll need to build the house. Your house will be constructed faster, cost less as a result, and probably be higher quality, provided you carefully selected the materials and konw how to use them.

    The second approach is analogous to sitting down to write a video game and using a prbuilt game engine. The game developers are able to focus on the gmae's content and don't need to know how to do complex calculations to figure out if two objects collided as they're flying through the aire because the game engine will do that for them. There's no need to construct an asset-loading system, write low-level code to read user-input, decompress sound files or parse animation file formats. It's unnecessary to build this functionality common to all video games because the game engine developers have already put thousands of hours into writing, testing, debugging, and optimizing code to do these things already.

    In conclusion...
    It's impossible to overstate the advantage that game engines give to the independent developer or the big-studio team working on the next hit game. Some developers want to write their own game engines as a programing exericse to learn how everything works under the hood, and they will learn a tremendous amount. But if your intentions is to ship a game, then you're doing yourself a disservice by not using a premade game engine.

    Game engines historically
    Historically game engines have sometmies been closely tied to the games themselves. In 1987, Ron Gilbert, along with some help from Chip Morningstar, created the SCUMM, or Script Creation Utility for Maniac Mansion game engine, while working at Lucasfilm Games. SCUMMis a great example of a game engine that was custom-made for a specific type of game. The "MM" in SCUMM stands for Maniac Mansion, which was a critically acclaimed adventure game and the first to use the point-and-click style interface, which Gilbert aslo invented.

    The SCUMM game engine was respnsible for converting scripts consisting of human-readable tokenized words such as "walk character to door" into byte-szied programs to be read by the game engine interpreter. The interpreter was responsible form controlling the game's actores on screen and presenting the sound and graphics. The ability to script gameplay instead of coding it, faciliated rapid prototyping and allowed the team to begin building and focusing on the gameplay formm an early state. Although the SCUMM engine was developed specifically for Maniac Mansion( Figure 1-1 ), it also was used for other hit games such as Full Throttle, The secret of Monkey Island, Indiana Jones and the Lst Crusade:The Graphic Adventure, and more.

    When compared with modern day game engines like Unity, the SCUMM engine lacks a great deal of flexibility, as it was custom-made for point-and-click style games. However, like Unity, the SCUMMengine allowed game developers to focus on gameplay instead of continuously rewriting graphics and sound code for each game, saving untold amounts of time and effort.

    Sometimes game engines can have an enormous impact on the industry as a whole. In mid-1991, a seismic shift in the industry occurred at a company named id Software, when 21-year-ld John Carmack built a 3D game engine for a game called Wolfenstein 3D. Up until then, 3D graphics were generally limied to slow-moving fight simulation games or games with simple polygons, because the available compter hardware was too slow to calculate and dsplay the number of surefaces necessary for a fast-paced 3D action game. Carmack was able to work around the current hardware limitations by using a graphics technique called raycasting. This allowed for fast display of 3D environments by calculating and displaying only the surfaces visible to the player, instead of the entire area arounjd the player.

    This uniqure approach allowed Carmack, along with John Romero, desinger Tom Hall, and artist Adrian Carmack to create a violent, fastpaced game about mowing down Nazis that spawned the first-person shooter(FPS) genre of video games. The Wolfenstein 3D engine was licensed by id Software to several other titles. They have produced seven game engines to date, which have been used in influential titles souch as Quake IIIArena, a Doom reboot, and Wolfenstein II:The New Colossus.

    These days, buiding a rough 3D FPS-game prototype is something an experienced game developer can do in a few days using a powerful game engine like Unity.

    Game engines today
    Modern-day AAA game development studios such as Bethesda Game Studios and Blizzard Entertainmnet often have their own in-house, proprietary game engines. Bethesda's in-house game engine is called: Creation Engine and was used to create The Elder Scrolls V: Skyrim as well as Fallout 4. Blizzard has their own proprietary game engine used to make games such as World of Warcraft and Overwatch.

    A proprietay in-house games engine may start out as built for a specific game project. After that project is released, the gmae engine often finds a new life when it's resued for the next ame coming out of that game studio. The engine might require upgrades to stay current and take advantage of the latest technology, but it doesn't need to be rebuilt from the ground-up.

    If a game developemnt companty doestn't have an in-house engine, they typically use an open-source engine, or license a third-party engine such as Unity. To create a significant 3D game these days without the use of a game engine would be an incredibly demanding task--financially as well as technologically. In fact, game studios with in-house game engines requre separte programing teams dedicated entirely to building out engine features and optimizing them.

    Having said all fo this, why would an AAA-studio choose not to use a game engine like Unity, but instead elect to build their own in-house enginge? Companies such as Bethesda and Blizzard have an enormous body of pre-exsting code to draw from, financial resources, and a wealth of deeoply talented programmers. For certain types of projects, they want complete control over every facet of their game and game engine.

    Even having all of these advantages over the typical small game studios, Bethesda still used Unity to develop the mobile game: Fallout Shelter; and Blizzard used Unity to develop a little cross-platform collectible cardgame: Hearthstone. When time equals money, a gam engine like Unity can be used to quickly prototype, build out, and iterate on functionality. The time = money equation is especially relevant if your plan is to release a gam eto multiple platforms. Porting an in-house engine to specific platforms such as iOSand Android can be time consuming. If a prject doesn't require the sma e level of control over the game engine that you would need when developing a game liek Ovjerwatch, using a cross-compatible game engine like Unity is a no-brainer.

    The unity game engine
    Unity is an extremely popular game engine that affords a huge number of advantages over other game engines available in the market today. Unity offers a visal workflow with frag-and-drop capabilities and supports scripting with C#, a very poopular programming languange. Unity has ong supperted 3D and 2D graphics, and the toolsets for both grow more sophisticated and user-friendly with each release.

    Unity has several tiers of licenses and is free for projects with revenues up to $100K. It offers cross-platfrom suppert for 27 differnet platforms and takes advantage of graphics APIs specific to the system architecture, including Direct #D, OpenGL, Vulkan, Meal, and several others.

    Unity teams offers cloud-based project collaboration and continuous intergration.
    Since its debut in 2005, Unity has been used to develop thousands of desktop, mobile, and console games and applications. A small sampling of some well-known titles deveoped ove the years with Unity would include: Thomas Vas Aline(2010), Temple Run(2011), The Room(2012), Rim World(2013), Hearthstone(2014), Kerbal Space Program(2015), Pokemon GO(2016), and Cuphead(2017), which is seen in Figyre 1-2.

    For game developers who want to customize their workflow, Unity affords the ability to extend the default visual editor. Thsi extremly powerful mechanism allows for the creatoin of custom tools, editors, and inspectors. Imagein creating a visual tool for your game designers to easily tweak values for in-game objects like hit-points for a character class, skill-trees, attack range, or item drops, without having to g into the code and modify values or use an exteranl database. This is alll made possible and straightforward by the Editor Extension functionality that Unity provides.

    Another Unity advantage is the Unity Asset Store. The Asset Store is an online storefront where artists, developers, and content creators can upload content ot be bought and sold. The Asset Store contains thousands of free and paid Editor Extensions, models, scripts, textures, shaders, and more, which teams cna sed to accelerate their deveopemnt timeines and enhande a final product.

    Summary
    In this chapter we leared about the many advantages ot using a premade game engine as opposed to writing your own. We touched on a couple of interesting game enginees of yesteryear and the impact they had on game development as a whole. We also outlined the specific advantages that Unity offers and mentioned some of the beter-known games developed using the Unity engine. Perhaps one day soon, someone will mention your game as one of the better known games made with Unity!

    相关文章

      网友评论

        本文标题:Developing 2D Games with Unity b

        本文链接:https://www.haomeiwen.com/subject/xlmswqtx.html