45,59 €
Master realistic animations and graphics, particle systems, game AI and physics, sprites and VR development with Unity 2017
If you are a Unity developer who now wants to develop and deploy interesting games by leveraging the new features of Unity 2017, then this is the book for you. Basic knowledge of C# programming is assumed.
Do you want to make the leap from being an everyday Unity developer to being a pro game developer? Then look no further! This book is your one-stop solution to creating mesmerizing games with lifelike features and amazing gameplay.
This book focuses in some detail on a practical project with Unity, building a first-person game with many features. You'll delve into the architecture of a Unity game, creating expansive worlds, interesting render effects, and other features to make your games special. You will create individual game components, use efficient animation techniques, and implement collision and physics effectively. Specifically, we'll explore optimal techniques for importing game assets, such as meshes and textures; tips and tricks for effective level design; how to animate and script NPCs; how to configure and deploy to mobile devices; how to prepare for VR development; how to work with version control; and more.
By the end of this book, you'll have developed sufficient competency in Unity development to produce fun games with confidence.
This book takes an easy-to-follow, step-by-step tutorial approach. You will create an advanced level Unity game with an emphasis on leveraging advanced Unity 2017 features while developing the game in its entirety.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 351
Veröffentlichungsjahr: 2017
BIRMINGHAM - MUMBAI
Copyright © 2017 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author(s), nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: January 2017
Second edition: October 2017
Production reference: 1271017
ISBN 978-1-78847-983-7
www.packtpub.com
Author
Alan Thorn
Copy Editor
Shaila Kusanale
Reviewers
Michael Miles
Alessandro Mochi
Project Coordinator
Devanshi Doshi
Commissioning Editor
Amarabha Banerjee
Proofreader
Safis Editing
Acquisition Editor
Larissa Pinto
Indexer
Pratik Shirodkar
ContentDevelopmentEditor
Onkar Wani
Graphics
Jason Monteiro
Technical Editor
Harshal Kadam
Production Coordinator
Arvindkumar Gupta
Alan Thorn is a multidisciplinary game developer, author, and educator with 17 years of industry experience. He makes games for PC desktop, mobile, and VR. He founded Wax Lyrical Games and created the award-winning game Baron Wittard: Nemesis of Ragnarok, working as designer, programmer, and artist. He has written 23 technical books on game development and presented 19 video training courses. These cover gameplay programming, Unity development, and 3D modeling and animation. He has worked in game education as a senior lecturer for Teesside University, a lead teacher for Uppingham School, and a visiting lecturer for London South Bank University. Currently, he's the Head of Department for Games Design and Development at the National Film and Television School.
Michael Miles is a manufacturing engineer working in the aerospace industry by day, and a Unity Game designer and C#, JavaScript, and Python developer the rest of the time. While he purchased his first computer in the early '80s, it was years later when he first got into programming, writing modifications for Doom during breaks at work. With gaming in general frowned upon, while working Michael put these skills to work, programming simulations for the various processes he used on the job. A few years later, he discovered Unity3D and Blender; using these applications, Michael creates interactive training and production-ready instruction tools for the assembly of parts for the aircraft his company builds.
When not in front of a computer screen, he likes to play card games, board games with family and friends, and immerse himself in books from fantasy to theoretical physics.
Alessandro Mochi has been playing video games since the Amstrad and NES era, tackling all possible fields: PC, console, and mobile. They are his love, and designing them is his passion, used as a medium to transmit and evoke emotions. He gives a lot of importance to details while doing any work, and is well versed in project and team management, communication, and problem-solving skills.
He is experienced in mechanical design, but is also quite good at programming (Unity, C#) and 3D modeling. With over 15 years of experience in IT and project management, he's currently pouring all of his heart and mind into the company he founded--Dapper Penguin Studios. Here, he tries to resurrect a lost genre in PC gaming--the industrial tycoon--with the flagship title Rise of Industry. Many studios have tried in recent years, and their failures serve as inspiration and fuel for his work, trying to give back to the gaming industry a fun, polished, and immortal experience.
For support files and downloads related to your book, please visit www.PacktPub.com. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.comand as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial process. To help us improve, please leave us an honest review on this book's Amazon page at https://www.amazon.com/dp/1788479831.
If you'd like to join our team of regular reviewers, you can email us at [email protected]. We award our regular reviewers with free eBooks and videos in exchange for their valuable feedback. Help us be relentless in improving our products!
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
Preparation and Asset Configuring
Getting clear on design
Target platforms
Intended audience
Genre
Game mode
Game objective
Asset preparation
Meshes - Work only with good topology
Meshes - Minimize polygon count
Meshes - Simulating bump details without geometry
Meshes - Minimize UV seams
Meshes - Export as FBX
Meshes - Use meters scale (metric)
Textures - Never use lossy compression
Textures - Power of 2 sizes
Textures - Alpha textures
Asset importing for Dead Keys
Importing textures
Importing meshes
Importing animations
Importing audio
Configuring materials
Summary
Level Design and Structure
Setting the scene with a skybox
Level building - Modular construction sets
Level building - Organization and structure
Level design - Tips and tricks
Objective and feedback
Narrative
Believability and convenience
Atmosphere and aesthetic
Simplicity and reuse
Level lighting - Preparation
Baked lighting
Dynamic lighting
Precomputed global illumination
Getting started with lightmapping
Baking lightmaps - Resolution and size
Baking lightmaps - Details
Light Probes
Lighting FAQ
Navigation mesh
Occlusion Culling
Creating a player camera
Particle systems
Music and audio
Summary
Player Controls - Movement
Player movement
Zombie combat
Creating player waypoints
Animating the camera
Configuring an animator graph
Working with animation - creating the navigator
Customizing and changing MonoDevelop
Singletons
Comments
Connecting to the navigator component
Comments
Navigator GUI
Input axes
The canvas
The button
Coding button behavior
Comments
Creating player death
Comments
Summary
Player Controls - Typing and Health
Word combat
Creating a word list
Using Visual Studio Code
Creating a WordList class
Comments
Comments
Matching words
Comments
The Typer object
Progressing with the Typer class
Comments
Health and damage
Comments
Comments
Damage and feedback
Player score
Comments
Bonus items
Comments
Summary
Enemies and Artificial Intelligence
Configuring the zombie character
Getting started with the zombie Prefab
Planning the zombie Artificial Intelligence
Comments
Developing state structure
Comments
Developing an NPC Animator Controller
Developing the Idle state
Comments
Developing the Chase state
Comments
Developing the Attack state and more
Comments
Developing the Dead state
Zombies and text input
Comments
Zombies and the Typer class
Comments
Comments
Activating enemies and camera paths
Working with Play mode
Summary
Project Management and Version Control
Project management
Research, design, and work assessment
Workload plan
Task status
Risk analysis
Resources and skills needed
Testing plan
Applied project management using Trello
Collaboration with cloud storage
Version control using Git
Getting started with Git and GitKraken
Commits and branches
Forward and backward with Git
Configuring Unity for version control
Reverting and discarding
Branches and branching
Conflicts and resolving
Git and the web
Pushing and pulling
Cloning
Summary
Persistent Data - Load and Save Game States
Data serialization
Player preferences - saving data
Player preferences - loading data
Player preferences - INI files
Comments on iniParser.cs
Saving data - XML files
Comments
Saving data - JSON files
Comments
Saving data - binary files
Comments
Saving data for Dead Keys
Comments
Summary
Performance, Optimization, Mobiles, and More
Stats and performance
Profiler and performance assessment
Optimization tips and tricks
Strings and comparisons
Beware of functions in disguise
Debug cleaning
Optimizing build size
Getting started with mobile development
Moving forward with mobile development
Building for Android
Building for VR (Virtual Reality)
Summary
Greetings and welcome to Mastering Unity 2017! This book begins from a beginner's knowledge of Unity, and it helps you develop that knowledge into mastery of a certain kind. Specifically, it develops a general, overarching mastery in which you’ll learn Unity like a seasoned indie developer, capable of turning your hand to pretty much any department and feature set within Unity. The following chapter outline explains, in more detail, the full range of features that we’ll see, but the central aim of this book is to make you versatile and powerful with Unity; capable of encountering a problem and being able to solve it in the language of Unity’s feature set. In this book, we’ll concentrate for the most part on a practical example; we’ll build a first-person combat game, across multiple chapters, and this will test your typing skills in more ways than one, so let’s go!
Chapter 1, Preparation and Asset Configuring, outlines the project we’ll focus on in the book. It specifies tips and tricks for importing assets optimally, configuring assets, and best-practice workflows for keeping your project organized.
Chapter 2, Level Design and Structure, here, gets you started with designing and building the main game level inside Unity, taking a look at interesting level-design ideas as well as critically important practical considerations.
Chapter 3, Player Controls - Movement, explores player controls, that is, how player input drives and controls the main game camera.
Chapter 4, Player Controls – Typing and Health, says that every character that can take damage needs health, representing the total amount of damage a character may sustain. In this chapter, we’ll focus on creating a combat mechanic that damages enemies.
Chapter 5, Enemies and Artificial Intelligence, informs that enemies need to behave intelligently and believably; this chapter looks at how to achieve that using AI. By using AI, enemies will move around the level, seeking the player, and will attack when in range.
Chapter 6, Project Management and Version Control, looks at ways to optimize the game development workflow using Version Control software. This keeps a record of our project as it moves through all its iterations.
Chapter 7, Persistent Data – Load and Save Game States, explains that players often want their in-game progress saved, allowing them to resume where they left off previously every time they start a new play session. This chapter covers the different saving methods available in Unity.
Chapter 8, Performance, Optimization, Mobiles, and More, outlines a selection of related topics as the final chapter of this book. Specifically, it takes you through how to improve the performance of your games through optimization, how to prepare your games for mobile deployment, and how to prepare generally for VR development.
To read this book effectively, and to complete the tasks within, you need only two things: first, the Unity 2017 software (which you can get for free from https://unity3d.com) and second, the determination to succeed! By using only these tools, you can learn to produce great games in Unity.
If you are a Unity developer who now wants to develop and deploy interesting games by leveraging the new features of Unity 2017, then this is the book for you. Basic knowledge of C# programming is assumed.
Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply email [email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files emailed directly to you. You can download the code files by following these steps:
Log in or register to our website using your email address and password.
Hover the mouse pointer on the
SUPPORT
tab at the top.
Click on
Code Downloads & Errata
.
Enter the name of the book in the
Search
box.
Select the book for which you're looking to download the code files.
Choose from the drop-down menu where you purchased this book from.
Click on
Code Download
.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
WinRAR / 7-Zip for Windows
Zipeg / iZip / UnRarX for Mac
7-Zip / PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Mastering-Unity-2017-Game-Development-with-C-Sharp. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/MasteringUnity2017GameDevelopmentwithCSharp_ColorImages.pdf.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title. To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the internet, please provide us with the location address or website name immediately so that we can pursue a remedy. Please contact us at [email protected] with a link to the suspected pirated material. We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.
Greetings, and welcome to this comprehensive and detailed exploration of Unity 2017 that carefully examines how we take a game project from conception to completion. Here, we'll pay special attention to the best-practice workflows, design elegance, and technical excellence. The project to be created will be a first-person cinematic shooter game, for desktop computers and mobile devices, inspired by Typing of the Dead (https://en.wikipedia.org/wiki/The_Typing_of_the_Dead). Our game will be called Dead Keys (hereon abbreviated as DK). In DK, the player continually confronts evil flesh-eating zombies, and the only way to eliminate them safely is to complete a set of typing exercises, using either the physical keyboard or a virtual keyboard. Each zombie, when they appear, may attack the player and is associated with a single word or phrase chosen randomly from a dictionary. The chosen phrase is presented clearly as a GUI label above the zombie's head. In response, the player must type the matching word in correct and full words, letter by letter, to eliminate the zombie. If the player completes the word or phrase without error, the zombie is destroyed. If the player makes a mistake, such as pressing the wrong letter in the wrong order, then they must repeat the typing sequence from the beginning.
This challenge may initially sound simple for the player, but longer words and phrases naturally give zombies a longer lifespan and greater opportunities for attacking. The player inevitably has limited health and will die if their health falls below 0. The objective of the player, therefore, is to defeat all zombies and reach the end of the level. Here's an illustration of the game:
Creating the word-shooter project involves many technical challenges, both 3D and 2D, and together, these make extensive use of Unity and its expansive feature set. For this reason, it's worth spending some time exploring what you'll see in this book and why. This book is a Mastering title, namely Mastering Unity 2017, and the word Mastering carries important expectations about excellence and complexity. These expectations vary significantly across people, because people hold different ideas about what mastery truly means. Some think mastery is about learning one specific skill and becoming very good at it, such as mastery in scripting, lighting, or animation. These are, of course, legitimate understandings of mastery. However, others see mastery more holistically, and this view is no less legitimate. It's the idea that mastery consists of cultivating a general, overarching knowledge of many different skills and disciplines, but in a special way by seeing a relationship between them and seeing them as complementary parts that work together to produce sophisticated and masterful results. This is a second and equally legitimate understanding of the term, and it's the one that forms the foundation for this book.
This book is about using Unity generally as a holistic tool--seeing its many features come together, as one unit, from level editing and scripting to lighting, design, and animation. For this reason, our journey will inevitably lead us to many areas of development, and not just coding. Thus, if you're seeking a book solely about coding, check out the Packt title on Mastering Unity Scripting. In any case, this book, being about mastery, will not focus on fundamental concepts and basic operations. It already assumes that you can build basic levels using the level editor and can create basic materials and some basic script files using C#. Though this book may at times include some extra, basic information as a refresher and also to add context, it won't enter into detailed explanations about basic concepts, which are covered amply in other titles. Entry-level titles from Packt include Unity 5.x By Example, Learning C# by Developing Games with Unity 5.x, and Unity Animation Essentials. This book, however, assumes that you have a basic literacy in Unity and want to push your skills to the next level, developing a masterful hand for building Unity games across the board.
So, with that said, let's jump in and make our game!
To build games professionally and maximize productivity, always develop from a clear design, whether on paper or in digital form. Ensure that the design is stated and expressed in a way that's intelligible to others, and not just to yourself. It's easy for anybody to jump excitedly into Unity without a design plan, assuming that you know your own mind best of all, and then to find yourself wandering aimlessly from option to option without any direction. Without a clear plan, your project quickly descends into drift and chaos. Thus, first produce a coherent game design document (GDD) for a general audience of game designers who may not be familiar with the technicalities of development. In that document, you will get clarity about some very important points before using development software, making assets, or building levels. These points, and a description, are listed in the following sections, along with examples that apply to the project we'll develop.
The target platform specifies the device, or range of devices, on which your game runs natively, such as Windows, Mac, Android, and iOS. This is the full range of hardware on which a potential gamer can play your game. The target platforms for DK include Windows, Mac, Android, iOS and the web:
Reaching decisions about which platforms to support is an important logistical and technical as well as political matter. Ideally, a developer wants to support as many platforms as possible, making their game available to the largest customer base. However, whatever the ideals may be, supporting every platform is almost never feasible, and so, practical choices have to be made. Each supported platform involves considerable time, effort, and money from the developer, even though Unity makes multi-platform support easier by doing a lot of low-level work for you. Developing for multiple-platforms normally means creating meshes, textures, and audio files of varying sizes and detail levels as well as adapting user interfaces to different screen layouts and aspect ratios, and also being sensitive to the hardware specifics of each platform.
Platform support also influences core game mechanics; for example, touchscreen games behave radically differently to keyboard-based games, and motion controls behave differently to mouse-based controls. Thus, a platform always constrains and limits the field of possibilities as to what can be achieved, not just technically, but also for content. App Store submission guidelines place strict requirements upon permissible content, language, and representations in games and allowed in-app purchases, and the access to external, user-created content.
The upshot is that target platforms should, for the most part, always be chosen in advance. That decision will heavily influence core game mechanics and how the design is implemented in a playable way. Sometimes, the decision to defer support for a particular platform can, and should, be made for technical or economic reasons. However, when such a decision is made, be aware that it can heavily increase development time further along the cycle, as reasonable adjustment and redevelopment may be needed to properly support the nuances of the platform.
The intended audience is like a personality profile. It defines, in short, who you're making the game for. Using some stereotyping, it specifies who is supposed to play your game: casual gamers, action gamers, or hardcore gamers; children or adults; English speakers or non-English speakers; or someone else. This decision is important especially for establishing the suitability of the game content and characters and difficulty of gameplay. Suitability is not just a matter of hiding nudity, violence, and profanity from younger gamers. It's about engaging your audience with relevant content--issues and stories, ideas that are resonant with them--and encouraging them to keep playing. Similarly, the difficulty is not simply about making games easier for younger gamers. It's about balancing rewards and punishments and timings to match audience expectations, whatever their age.
As with target platform, you should have a target audience in mind when designing your game. This matters especially for keeping focused when including new ideas in your game. Coming up with fun ideas is great, but will they actually work for your audience in this case? If your target audience lacks sufficient focus, then some problems, such as the following, will emerge:
Your game will feel conceptually messy (a jumble of disconnected ideas)
You'll struggle to answer how your game is fun or interesting
You'll keep making big and important changes to the design during its development
For these reasons, and more, narrow your target audience as precisely as possible, as early as possible.
For Dead Keys, the target audience will be over 15 years of age and Shoot 'Em Up fans who also enjoy quirky gameplay that deviates from the mainstream. A secondary audience may include casual gamers who enjoy time-critical word games.
Genre is primarily about the game content: what type of game is it? Is it RPG, first-person shooter, adventure, or any other type? Genres can be even narrower than this, such as fantasy MMORPG and cyberpunk adventure game, or competitive deathmatch, first-person shooter. Sometimes, you'll want the genre to be very specific, and other times you'll not, depending on your aims. Be specific when building a game in the truest and most genuine spirit of a traditional, well-established genre. In this case, the idea is to do a good job at a tried and tested formula. In contrast, avoid too narrow a definition when seeking to innovate and push boundaries. Feel free to combine the existing genres in new ways or, if you really want a challenge, to invent a completely new genre.
Innovation can be fun and interesting, but it's also risky. It's easy to think that your latest idea is clever and compelling, but always try it out on other people to assess their reactions and learn to take constructive criticism from an early stage. Ask them to play what you've made or to play a prototype based on the design. However, avoid relying too heavily on document-based designs when assessing fun and playability, as the experience of playing is radically different from reading and the thoughts it generates.
For Dead Keys, the genre will be a cinematic first-person zombie-typer! Here, our genre takes the existing and well-established first-person shooter tradition, but (in an effort to innovate) replaces the defining element of shooting with typing.
The term game mode might mean many things, but in this case, we'll focus on the difference between singleplayer and multiplayer game modes. Dead Keys will be single player, but there's nothing intrinsic about its design that indicates that it is for a single player only. It can be adapted to both local co-op multiplayer and internet-based multiplayer (using the Unity networking features). More information on Unity network, for the interested reader, can be found online at: https://docs.unity3d.com/Manual/UNet.html.
It's important to decide on this technical question very early in development, as it heavily impacts how the game is constructed and the features it supports.
Every game (except for experimental and experiential games) needs an objective for the player, something they must strive to do, not just within specific levels, but across the game overall. This objective is important not just for the player (to make the game fun), but also for the developer to decide how challenge, diversity, and interest can be added to the mix. Before starting development, have a clearly stated and identified objective in mind.
Challenges are introduced primarily as obstacles to the objective--and bonuses are things that facilitate the objective--that make it possible and easier to achieve. For Dead Keys, the primary objective is to survive and reach the end of each level. Zombies threaten that objective by attacking and damaging the player, and bonuses exist along the way to make things more interesting.
When you've reached a clear decision on the initial concept and design, you're ready to prototype! This means building a Unity project demonstrating the core mechanic and game rules in action as a playable sample. After this, you typically refine the design more, and repeat prototyping until arriving at an artifact you want to pursue. From here, the art team must produce assets (meshes and textures) based on the concept art, the game design, and photographic references. When producing meshes and textures for Unity, some important guidelines should be followed to achieve optimal graphical performance in-game. This is about structuring and building assets in a smart way so that they export cleanly and easily from their originating software and can then be imported with minimal fuss, performing as best as they can at runtime. Let's take a look at some of these guidelines for meshes and textures.
A good mesh topology consists of all polygons having only three or four sides in the model (not more). Additionally, edge loops should flow in an ordered, regular way along the contours of the model, defining its shape and form:
On import, Unity automatically converts any NGons (polygons with more than four sides) into triangles, if the mesh has any. However, it's better to build meshes without NGons as opposed to relying on Unity's automated methods. Not only does this cultivate good habits at the modeling phase, it also avoids any automatic and unpredictable re-topology of the mesh, which affects how it's shaded and animated.
Every polygon in a mesh entails a rendering performance hit insofar as a GPU needs time to process and render each polygon. Consequently, it's sensible to minimize the number of a polygons in a mesh, even though modern graphics hardware is adept at working with many polygons. It's a good practice to minimize polygons wherever possible and to the degree that it doesn't detract from your central artistic vision and style:
There are many techniques available to reduce polygon counts. Most 3D applications (such as 3Ds Max, Maya, and Blender) offer automated tools that decimate polygons in a mesh while retaining their basic shape and outline. However, these methods frequently make a mess of topology, leaving you with faces and edge loops leading in all directions. Even so, this can still be useful for reducing polygons in static meshes (meshes that never animate), such as statues, houses, or chairs. However, it's typically bad for animated meshes where topology is especially important:
As mentioned, try keeping meshes as low-poly as possible. Low-poly meshes are, however, of lower quality than higher-resolution meshes. They have fewer polygons and thereby hold fewer details. Yet, this need not be problematic. Techniques exist for simulating detail in low-poly meshes, making them appear at a higher resolution than they really are. Normal Mapping is one example of this. Normal Maps are special textures that define the orientation and roughness of a mesh surface across its polygons and how those polygons interact with lighting. In short, a Normal Map specifies how lighting interacts over a mesh and ultimately effects how the mesh is shaded in game. This influences how we perceive the details--how bumpy and rough a surface is. The extent of bump and detail is controlled by pixels in the Normal Map. You can produce Normal Maps in many ways, for example, typically using 3D modeling software. By producing two mesh versions in 3D Modelling Software (namely, a high-poly version containing all the required details sculpted into the model, and a low-poly version to receive the details), you can bake normal information from the high-poly mesh to the low-poly mesh via a texture file. That is, you can sculpt a high-resolution mesh and then transfer the details from the high-res to the low-res version by saving the detail to a Normal Map. This approach (known as Normal Map Baking) can lead to stunningly accurate and believable results, as follows:
However, if you don't have any Normal Map for an imported mesh, Unity can generate them from a standard, diffuse texture via the Normal Import Settings. This may not produce the most believable and physically accurate results, like Normal Map Baking, but it's useful to quickly and easily generate displacement details, enhancing the mood and realism of a scene. To create a Normal map from a diffuse texture, first select the imported texture from the Project panel and duplicate it; ensure that the original version is not invalidated or affected. Then, from the object Inspector, change the Texture Type (for the duplicate texture) from texture to Normal map. This changes how Unity understands and works with the texture:
Specifying Normal Map for a texture configures Unity to use and work with that texture in a specialized, optimized way for generating bump details on your model. However, when creating a Normal Map from a diffuse texture, you'll also need to enable the Create from Grayscale checkbox. When enabled, Unity generates a Normal Map from a grayscale version of the diffuse texture, using the Bumpiness and Filtering settings, as follows:
With Create from Grayscale enabled, you can use the Bumpiness slider to intensify and weaken the bump effect and the Filtering setting to control the roughness or smoothness of the bump. When you've adjusted the settings as needed, confirm the changes and preview the result by clicking on the Apply button from the Inspector object:
Seams are edge cuts inserted into a mesh during UV mapping to help it unfold, flattening out into a 2D space for the purpose of texture assignment. This process is achieved in 3D modeling software, but the cuts it makes are highly important for properly unfolding a model and getting it to look as intended inside Unity. An edge is classified as a seam in UV space when it has only one neighboring face, as opposed to two. Essentially, the seams determine how a mesh's UVs are cut apart into separate UV shells or UV islands, which are arranged into a final UV layout. This layout maps a texture onto the mesh surface, as follows:
Always minimize UV seams where feasible by joining together disparate edges, shells, or islands, forming larger units. This is not something you do in Unity, but in your 3D modeling software. Even so, by doing this, you potentially reduce the vertex count and complexity of your mesh. This leads to improved runtime performance in Unity. This is because Unity must duplicate all vertices along the seams to accommodate the rendering standards for most real-time graphics hardware. Thus, wherever there are seams, there will be a doubling up of vertices, as shown here:
Unity officially supports many mesh import formats, including .ma, .mb, .max, .blend, and others. Details and comparisons of these are found online at: http://docs.unity3d.com/Manual/3D-formats.html. Unity divides mesh formats into two main groups: exported and proprietary. The exported formats include .fbx and .dae. These are meshes exported manually from 3D modeling software into an independent data-interchange format, which is industry recognized. It's feature limited, but widely supported. The proprietary formats, in contrast, are application-specific formats that support a wider range of features, but at the cost of compatibility. In short, you should almost always use the exported FBX file format. This is the most widely supported, used, and tested format within the Unity community and supports imported meshes of all types, both static and animated; it gives the best results. If you choose a proprietary format, you'll frequently end up importing additional 3D objects that you'll never use in your game, and your Unity project is automatically tied to the 3D software itself. That is, you'll need a fully licensed copy of your 3D software on every machine for which you intend to open your Unity project; this is annoying:
Unity measures 3D space using the metric system, and 1 world unit is understood, by the physics system, to mean 1 meter. Unity is configured to work with models from most 3D applications using their default settings. However, sometimes your models will appear too big or small when imported. This usually happens when your world units are not configured to metric in your 3D modeling software. The details of how to change units varies for each piece of software, such as Blender, Maya, or 3Ds Max. Each program allows unit customization from the Preferences menu: