1. Trang chủ
  2. » Kinh Doanh - Tiếp Thị

Unity 2017 game development essentials, third edition

948 52 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 948
Dung lượng 29,8 MB

Nội dung

Unity 2017 Game Development Essentials Third Edition Build fully functional 2D and 3D games with realistic environments, sounds, physics, special effects, and more! Tommaso Lintrami BIRMINGHAM - MUMBAI Unity 2017 Game Development Essentials Third Edition Copyright © 2018 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, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been 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 Commissioning Editor: Wilson D'souza Acquisition Editor: Reshma Raman Content Development Editor: Roshan Kumar Technical Editor: Harshal Kadam Copy Editor: Safis Editing Project Coordinator: Devanshi Doshi Proofreader: Safis Editing Indexer: Aishwarya Gangawane Graphics: Jason Monteiro Production Coordinator: Shraddha Falebhai First published: October 2009 Second edition: December 2011 Third edition: January 2018 Production reference: 1250118 Published by Packt Publishing Ltd Livery Place 35 Livery Street Birmingham B3 2PB, UK ISBN 978-1-78646-939-7 www.packtpub.com To my mother's memory, Carmela Bandera, who always believed in me and granted me my inclination toward IT and a good education Thanks to my sister Viola, my partner Silvia, and my beloved Zoe, who grew up and took her first steps while this book was taking life, and who gives me daily inspiration for my creativity – Tommaso Lintrami mapt.io Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career For more information, please visit our website Why subscribe? Spend less time learning and more time coding with practical e-books and videos from over 4,000 industry professionals Improve your learning with Skill Plans built especially for you Get a free e-book or video every month Mapt is fully searchable Copy and paste, print, and bookmark content PacktPub.com Did you know that Packt offers e-book versions of every book published, with PDF and ePub files available? You can upgrade to the e-book version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the e-book copy Get in touch with us at service@packtpub.com 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 e-books Contributors About the author Tommaso Lintrami has been programming games right from the age of 9; he studied music, micro electronics, and TV/cinema/game direction, and is a designer, developer, composer, and writer He is a virtual reality and interactive installations enthusiast with at least 19 years, commercial experience working for several IT companies He has been working with Unity for over years now and delivers IT teaching and training in Unity He has worked on a number of games on different platforms and is currently employed at Freejam, working on Robocraft About the reviewers Ludovico Cellentani is a senior engine programmer at King AB, and he has been working as a professional game programmer for almost 20 years During this time, he has worked on a number of games released on various platforms that span between PC, console, and mobile During the last years, he has worked on a considerable number of games, VR experiences, and gamification projects released for PC, mobile, and custom-built computer installations, all powered by the Unity game engine He is currently living with his wife and son in Stockholm, Sweden Adam Larson has been a programmer on 15 titles across major consoles and PC platforms He has worked on more than 50 mobile applications, with a few mobile games reaching more than a million downloads Today, he runs and operates a studio in Green Bay, Wisconsin, called Zymo Interactive, where they focus on using high-end gaming lessons in business and mobile applications His passion for building great products has led his team to work on some incredible projects in almost every conceivable industry Adam volunteers on the TEALS program to help get computer science in every high school across the United States He also teaches part-time as an adjunct professor at the University of Green Bay Adam is a father of three children and husband to Autum Larson You may just find the five of them out playing Pokemon Go together Elias Tsiantas has been a programmer and content creator on five titles on mobile and PC platforms Today, he works as a freelancer creating custom applications and/or content for companies on request His passion is The Inspector for our GameObject holding the FPSCounter component We will take advantage of the ready-made script in the Assets/Standard Assets/Utility folder Add it to the inspector by adding a component with the Add Component button and search FPSCounter to find the C# script and add it to the game object As you can see, it starts by adding an additional using directive, using UnityEngine.UI; This namespace will allow us to use a UI-related component API Now, because we might wish to make this a script that we can reuse for other games, we should ensure that it can be dropped onto an object in another project and still work perfectly Part of doing this is ensuring that the script contains the [RequireComponent ] directive to ensure that a UI Text component is present We have used these before, so hopefully you remember how; if not, you need to add [RequireComponent(typeof (Text))] Now, press Play and test your scene; you will see the UI Text displaying the frame rate at the bottom-left corner of the screen: Your game will perform differently outside the Unity Editor As such, readings from this FPS display should only be noted once the game is built and run either as a web player or a standalone version; ask your test users to note the lowest and highest frame rates to give you a range of readings to consider, and if there are particularly demanding parts of your game, for example, complex animation or particle effects, then it can be worth asking for readings from these separately As the game performs differently outside the Unity Editor, the player needs to play the game at least in full HD resolution for the higher resolution, which is 1920x1080 pixels, a resolution you will hardly have on the Game view Unless you detach it from the editor and extend widely, the values from this frame rate display will be different from those given in the Stats tab of the Game view Testing different resolutions video You can quickly test different aspect ratio video resolutions by adding presets to the Game window Click on the drop-down menu before the zoom scale view slider to quickly choose among the widely diffused 4:3, 16:9, or 16:10, or add a preset with a fixed custom video resolution or with a different aspect ratio with the plus (+) button, as illustrated: In this way, you will have the chance to switch the final output video resolution while the game is running and test all possible cases This is also very useful with the mobile platform when you don't have all the possible devices on the market available to be able to test all their different video resolutions, but you have to Optimizing more Improving the performance of your game as a result of testing is easily an entire field of study in itself However, to improve your future development, you'll need to be aware of basic economizing in the following ways: Spotting bottlenecks: Your game's performance may suffer due to a number of things; the key is to spot where this is happening, is a certain scene causing lower performance? Is the game only slower when encountering a high-detail model or high-output particle system? Try and be systematic when searching for what is making your game run slowly, and always ask your test users for a scenario you can reproduce in order to spot the problem Polygon counts: When introducing 3D models, they should be designed with low polygon counts in mind So, try and simplify your models as much as possible to improve performance Draw distance: Consider reducing the distance of your far clip plane in your cameras to cut down the amount of scenery the game must render Occlusion culling: Only available in the Pro version of Unity, occlusion culling helps avoid overdraw-rendering of unnecessary objects that are in front of one another in your camera view There's more on this in the online Unity manual at http://unity3d.com/support/documentation/Manual/Occlus ionCulling.html Texture sizes: Including higher-resolution textures can improve the visual clarity of your game, but they also make the engine work harder So, try and reduce texture sizes as much as possible, using both your image editing software and the Unity import settings of your texture assets Script efficiently: As there are many approaches to differing solutions in scripting, try and find more efficient ways to write your scripts Start by reading the Unity guide to efficient scripting online, available at http: //unity3d.com/support/documentation/ScriptReference/index.Performance_Optimizatio n.html Approaches to learning As you progress in this book, you will need to develop an approach to further study, which keeps a balance between personal perseverance and the need to ask for help from more experienced Unity developers Follow the advice laid out here, and you should be well on your way to helping other community members as you expand your knowledge Don't reinvent the wheel This may seem incongruous in view of the previous point, but as you start tackling more complex tasks in your game development, you'll learn that there is little point in reinventing the wheel, recreating something that another developer has already solved and offered to the community For example, if you are tackling the task of enemy AI or smart camera behaviors or anything you might need for your project, it is worth looking at the various solutions that might be available to you for this, rather than writing your own code from scratch There are many plugins and ready-made assets for Unity available to solve almost any task, available primarily from the Asset Store window inside the editor (Window | Asset Store) and from various sites across the web I recommend that you check out the next two sections and the links for extensions and content that have already been created by Unity Technology and third parties, which can help a lot with your game development Editor extensions Editor extensions are plugins that are written in Unity itself, taking advantage of the existing Unity Editor UI It's incredible how many things can be done just by extending the Editor Some of them are paid, and some are free from Unity Technologies, but they all are worth checking out and using As the latest Unity release has integrated some of these packages to be builtin the editor, I will group them in: Recenty built-in, on the Asset Store from Unity Technology and on the Asset Store from third parties Recently built-in: Text Mesh Pro: A new pixel-perfect geometric mesh-based UI solution to display text Timeline: A new fully-fledged animation system for the direction of complex cut scenes and movies On the Asset Store from Unity Technology: Cinemachine: This virtual camera system allows developers to build a solid and compact cinema director setup that is perfect for storytelling, FPS, adventure games, and other titles This package fits particularly well with the Timeline feature; get it from: http://u3d.as/GJQ PostProcessing Stack: This extension allows you to bake multiple camera post-processing effects into one single pass, saving performance and taking your game to the next level You can find it at http://u3d.as/KT p On the Asset Store from third parties: PlayMaker: This useful plugin allows you to design your game logic, or part of it, with a powerful visual node system Rumors say PlayMaker might become built-in with future versions of Unity AQUA water/river set: When you want to take your water simulation to the next level: http://u3d.as/mVN Enviro sky and weather: For a dynamic sky and sunlight as well as weather conditions simulator, look at http://u3d.as/cGY Anima: A fantastic package to add skeletal animation and physics to your 2D game characters: http://u3d.as/GGE Lips Sync pro: This editor extension uses an external sound processor to optimize the speed of automatic speech detection calculation, and is the best solution out there to implement lips sync with speech audio in your game It can use both Blendshapes or Bone animation Also, check out their Eye Blink solution to let your characters blink their eyes (uses blendshapes as well) Rewire: Cross-platform advanced input system solution: http://guavaman.c om/projects/rewired/ Fabric: Extends Unity’s audio functionality and provides an extensive set of high-level audio components that allow the creation of complex and rich audio behaviors: http://www.tazman-audio.co.uk/fabric Streaming AudioSource for WebGL: This package, available at http:// u3d.as/Dk2, implements basic support for streaming audio sources in Unity WebGL If you need to play background music or use some simple 3D sound, consider using this optional drop-in replacement for standard audio sources for Unity WebGL It's designed to optimize memory consumption in your WebGL project In the Chapter 13, Optimization and Final Touches, addendum folder of the codes project, you will find a full ending cut scene made with Timeline Cinemachine and the new Post Processing Stack to load when the puzzle of the game level is completed Take your time looking at how this scene is prepared and be ready to learn how to movies with Unity! Complete projects Complete projects are fully fledged assets you can download on the Asset Store that include not just an extension or a package to plug into an existing project, but full projects on their own, generally with the purpose of making the base for your game, or giving you instructions and inspirations for development: Lighting Optimization Tutorial: http://u3d.as/BNc Adventure Sample Game: http://u3d.as/DRi Tactical Shooter AI: http://u3d.as/k5F Vehicle Tools: http://u3d.as/KJn Racing Game Template: http://u3d.as/i2s Viking Village: http://u3d.as/bqF Survival Shooter Tutorial: a 2.5D game making tutorial http://u3d.as/hC f Space Shooter Tutorial: a 2.5D vertical scrolling space shoot them up: http://u3d.as/66k This is just a very small partial selection of what you can find on the store, and much more is appearing every day If you don't know how to it, just ask! Another useful approach to learning is, of course, to look at how others approach each new game element you attempt to create In game development, what you'll discover is that often there are many approaches to the same problem, as we learned in Chapter 5, Character Animation with Unity, while making our character open the outpost door As a result, it is often tempting to recycle skills learned when solving a previous problem, but I always recommend double-checking that your approach is the most efficient way By asking in the Unity forum (forum.unity3d.com), answers page (answers.unity3d com), or on the Internet Relay Chat (IRC) channel (irc.freenode.net, room #unity3d), you'll be able to gain a consensus on the most efficient way to perform a development task, and sometimes even discover that the way in which you first thought of approaching your problem was more complicated than it needed to be! When asking questions in any of the aforementioned places, always remember to first search whether your question has been asked before It most likely has been, but if not, when asking, remember to include the following points whenever possible: What are you trying to achieve? What you think is the right approach? What have you tried so far? This will give others the best shot at helping you out; by giving as much information as possible, even if you think it may not be relevant, you will give yourself the best chance of achieving your development goals If asking for help with scripting, always remember to use a pasting site, such as http://w ww.pastebin.com, in order to show your code to others without taking up pages of chat room space The great thing about the Unity community is that it encourages learning by example Online, you can find a wide range of examples of everything from scripts to plugins, tutorials, and more Here, you'll find useful and free-to-use code snippets to supplement the examples of scripted elements within the script reference, and also find information on how to implement it with example downloadable projects If you can't find your answer there, you can still try asking at Stack Exchange or look on the many other wikis/blogs or on the many GitHub repositories of Unity projects around the globe Summary In this chapter, we looked at how you can export your game to the web and as a standalone project, as well as for the two main mobile platforms, Android and iOS In conclusion, we'll look back at what you have learned over the course of this book and suggest ways in which you can progress further with the existing skills you have developed and where to look for continued assistance, help, and support with your Unity development We have discussed ways that you should move on from this book, and how you can gather information from test users to improve your game Also, check my upcoming blog at tutorials.litobyte.com for addendums and tutorials on AI, VR, Timeline and Cinemachine All that remains is to wish you the best of luck with your future game development in Unity From myself and everyone involved with this book, thanks for reading, and I hope you enjoyed the ride—it's only the beginning! Other Books You May Enjoy If you enjoyed this book, you may be interested in these other books by Packt: Mastering Unity 2017 Game Development with C# - Second Edition Alan Thorn ISBN: 978-1-78847-983-7 Explore hands-on tasks and real-world scenarios to make a Unity horror adventure game Create enemy characters that act intelligently and make reasoned decisions Use data files to save and restore game data in a way that is platformagnostic Get started with VR development Use navigation meshes, occlusion culling, and Profiler tools Work confidently with GameObjects, rotations, and transformations Understand specific gameplay features such as AI enemies, inventory systems, and level design Unity 2017 Game AI programming - Third Edition Ray Barrera, Aung Sithu Kyaw, Thet Naing Swe ISBN: 978-1-78847-790-1 Understand the basic terminology and concepts in game AI Explore advanced AI Concepts such as Neural Networks Implement a basic finite state machine using state machine behaviors in Unity 2017 Create sensory systems for your AI and couple it with a Finite State Machine Wok with Unity 2017's built-in NavMesh features in your game Build believable and highly-efficient artificial flocks and crowds Create a basic behavior tree to drive a character's actions Leave a review - let other readers know what you think Please share your thoughts on this book with others by leaving a review on the site that you bought it from If you purchased the book from Amazon, please leave us an honest review on this book's Amazon page This is vital so that other potential readers can see and use your unbiased opinion to make purchasing decisions, we can understand what our customers think about our products, and our authors can see your feedback on the title that they have worked with Packt to create It will only take a few minutes of your time, but is valuable to other potential customers, our authors, and Packt Thank you! .. .Unity 2017 Game Development Essentials Third Edition Build fully functional 2D and 3D games with realistic environments, sounds, physics, special... physics, special effects, and more! Tommaso Lintrami BIRMINGHAM - MUMBAI Unity 2017 Game Development Essentials Third Edition Copyright © 2018 Packt Publishing All rights reserved No part of... what you think Preface Game engines such as Unity are the power tools behind the games we know and love Unity is one of the most widely used and best loved packages for game development and is used

Ngày đăng: 15/09/2020, 11:38