29,99 €
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 by everyone, from hobbyists to large studios, to create games and interactive experiences for the Web, desktop, mobile, and console. With Unity's intuitive, easy-to-learn toolset and this book, it's never been easier to become a game developer.
You will begin with the basic concepts of Android game development, a brief history of Android games, the building blocks of Android games in Unity 5, and the basic flow of games. You will configure an empty project for the Jetpack Joyride Clone Game, add an environment and characters, and control them. Next you will walk through topics such as particle systems, camera management, prefabs, animations, triggers, colliders, and basic GUI systems. You will then cover the basic setup for 3D action fighting games, importing models, textures and controlling them with a virtual on-screen joystick. Later you will set up Scene for 3D Configuration, create basic gameplays, and manage input controls. Next you will learn to create the interface for the main menu, gameplay, game over, achievements, and high score screens. Finally you will polish your game with stats, sounds, and Social Networking, followed by testing the game on Android devices and then publishing it on Google Play, Amazon, and OUYA Stores.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 253
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 authors, 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: May 2017
Production reference: 1180517
ISBN 978-1-78355-077-7
www.packtpub.com
Authors
Siddharth Shekar
Wajahat Karim
Project Coordinator
Vaidehi Sawant
Reviewers
Asema Hassan
Engin Polat
Proofreader
Safis Editing
Acquisition Editor
Shweta Pant
Indexer
Pratik Shirodkar
Content Development Editor
Zeeyan Pinheiro
Graphics
Abhinash Sahu
Technical Editor
Pavan Ramchandani
Production Coordinator
Aparna Bhagat
Copy Editor
Safis Editing
Siddharth Shekar is a game developer with over 5 years of experience in the game development industry and 11 years of experience in C++, C#, and other programming languages. He is adept at graphics libraries and game engines such as Unity and Unreal Engine. He has also published games on the app stores of iOS, Android, Amazon, and Windows.
Siddharth is the author of the books Learning Cocos2d-x Game Development, Learning iOS 8 Game Development Using Swift, and Cocos2d Cross-Platform Game Development Cookbook and the technical reviewer for iOS Programming Cookbook, all by Packt Publishing.
Currently, he is a lecturer at the games department at Media Design School, Auckland, New Zealand. He teaches graphics programming and PlayStation 4/PS Vita native game development and mentors final year production students.
To know more about Media Design School on their website. You can also find Siddharth on Twitter at @sidshekar.
Wajahat Karim is a seasoned mobile app and game developer with extensive experience in diversified technologies, as well as more than 7 years of software development experience.
Wajahat received his information and communication systems engineering degree from the NUST School of Electrical Engineering and Computer Sciences (SEECS), Islamabad, Pakistan. He has been working on games since he was 14 years old and is skilled in many platforms, including Android SDK, AndEngine, Adobe Flash, Adobe AIR, Game Maker, and Unity3D.
He is skilled, not only in programming and coding, but also in computer graphic designing tools such as Adobe Photoshop, Adobe Illustrator, Adobe Flash, and Autodesk Maya. Recently, he also worked with the government of Oman in Muscat, to create a real-time election monitoring app for Android and iOS for their Shura Elections, 2015. He has run multiple startups from time to time and has also worked in a virtual reality and augmented reality startup.
Currently, besides being a full-time development manager at a multinational company, he is working with a startup that allows Android developers to boost their app growth and reward their users through in-app perks.
Wajahat has deep passion in game development, entrepreneurship, and writing. He has previously coauthored the book Learning Android Intents by Packt Publishing.
You can reach Wajahat on his personal website.
Asema Hassan is a game developer, AI researcher, and tutor. She is currently writing her master’s thesis at Otto von Guericke University, Magdeburg, Germany. Her major research focus is on artificial intelligence in games. She also works part time at the German Center for Neurodegenerative Diseases, where she develops 3D VR simulations in Unity along with her team.
She previously worked in Pakistan's game industry for almost 3 years. At Agnitus, she worked as a software engineer for more than 2 years and developed various 2D/2.5D games for Android/iOS. She has deep knowledge of Unity Engine, C#, and C++. She is also a supervisor for the PakGamers community, where her main responsibility is to guide new students on the game development process.
She likes to travel a lot and take photographs. You can find out more about her on http://asemahassan.blogspot.de.
Engin Polat has been involved in many large-scale and medium-scale projects on .NET technologies as a developer, architect, and consultant and has won many awards since 1999.
Since 2008, he has been conducting training for many large enterprises in Turkey on Windows development, web development, distributed application development, software architecture, mobile development, cloud development, and so on.
Apart from this, he organizes seminars and events in many universities in Turkey on .NET technologies, Windows platform development, cloud development, web development, game development, and so on.
He shares his experiences on his personal blog (http://www.enginpolat.com).
He has MCP, MCAD, MCSD, MCDBA, and MCT certifications.
In 2012, he was recognized as a Windows development MVP (Most Valuable Professional) by Microsoft, and in 2017, he got recognized as a Visual Studio and Development Technologies MVP too.
Between 2013 and 2015, he was recognized as a Nokia Developer Champion; very few people in the world are given this award. In 2015, he was recognized as the regional director by Microsoft.
He has worked on several books by Packt, including Mastering Cross Platform with Xamarin, Xamarin Blueprints, Xamarin by Example, and Mastering Xamarin UI Development.
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/1783550775.
If you'd like to join our team of regular reviewers, you can e-mail 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
Introduction to Android Game Development with Unity3D
Introduction to Android
Android versions
Google Play - the market store for Android
Unity3D and game engines
Unreal Engine
Adobe Flash professional
Game Maker Studio
Unity3D
Features of Unity3D
Basics of Unity game development
Unity editor interface
Scene View
Transform tools
Scene View navigation
Scene View control bar
Game View
Game View control bar
Hierarchy View
Project browser panel
Inspector panel
Configuration of empty game projects
Perky Penguin game
Perky Penguin gameplay
Adding the penguin
Importing the penguin Sprite
Creating penguin game object
Adding script behavior on penguin object
Limiting the penguin between screen bounds
Summary
Finishing the Perky Penguin 2D Game
Adding Particle Systems
What is a Particle System?
Basics of Particle System
Creating a rocket fire Particle Effect for a game
Adding game-level backgrounds
Camera management
Making the penguin move forward
Making the camera follow the Penguin
Prefabs and level management
Prefabs
Creating a Level Block Prefab
The level block generator concept
The BlockGenerator.cs code
Adding ice spikes to the game
Summary
Adding Player Character for an Action Fighting Game
Configuring Project for 3D Games in Unity
Importing 3D models
3D models
Modelling tools
Importing 3D models in Unity3D
Importing FBX Model
Applying textures and materials
Textures
Texture Importer
Applying texture in shaders
Shaders
Materials
Applying textures on a farmhouse model
Generic and humanoid rigs
What are humanoid characters?
Importing humanoid models
Configuring the avatar of humanoid models
Humanoid animation using Unity
Legacy Animation System
Mecanim animation system
Creating layer character for the fighting game
Summary
Enemy Characters with AI
Importing the player model
Player Animation Controller
Scripting player controls
Adding an enemy character
Enemy behavior and AI
Finalizing the fight
Summary
Gameplay, UI, and Effects
Finishing up gameplay
Understanding Unity uGUI
Adding GUI for health and gameover
Introduction to Particle Effects
Creating confetti Particle Effect
Summary
GameScene and SceneFlow
Adding buttons to the startScene
Organizing the folder structure
Adding a game restart button in the startScene
Adding a pause button to the startScene
Adding a main menu button to the startScene
Creating MainMenu scene
Summary
Gamestats, Social, IAP, and Ad Integration
Running the app on the device/ emulator
Android Developer Console
Adding achievements in the game
Saving game stats
Ad integration
In-App purchasing
Adding social media integration
Summary
Sound, Finishing Touches, and Publishing
Adding sound
Handling multiple resolutions
Optimizing the APK
Preparing the build for publishing
Publishing the game
Summary
Unity has come a long way from its humble beginnings; however, since the last couple of years, it has almost become an industry-wide used tool that almost all independent game developers use to develop their games. It is very easy to use to develop prototypes, and when you have a successful idea, it is flexible enough to expand the small prototype to a full-fledged game.
Despite its professional capacity, Unity is so simple to use that even a complete novice person can develop a basic game within a matter of hours. And with a little more effort, a very polished game can be developed with excellent lighting and animation.
With the current version, Unity makes game development even more accessible to everyone.
In this book, we will cover a variety of topics both in 2D and 3D game development. We will see how to develop a game similar to JetPack Joyride in 2D, and a 3D fighting game with full 3D animation, lighting, and camera. We will also see how to add buttons, text, and screen transitions. Finally, once we have created the game, we will see how to monetize it by adding in-app purchases and ads.
Chapter 1, Introduction to Android Game Development with Unity3D, covers the basic concepts of Android game development, a brief history of Android games, the building blocks of Android games in Unity3D, and the basic flow of games.
Chapter 2, Finishing the Perky Penguin 2D Game, extends 2D game development by finishing the Jetpack Joyride clone game. The chapter introduces various topics, such as particle systems, camera management, prefabs, animations, triggers, colliders, and basic GUI systems.
Chapter 3, Player Character for Action Fighting Game, covers the basic setup for 3D action fighting game, importing models and textures, setting rigging for the characters, applying animations on models, and controlling the player character with a virtual on-screen joystick.
Chapter 4, Enemy Character with AI, covers the aspect of creating the enemy model of the game from importing models to applying animations to decision making with AI.
Chapter 5, Gameplay, UI, and Effects, shows how to finish the gameplay loop, add a UI, add text for scoring the game, and add particle effects to the game.
Chapter 6, GameScene and SceneFlow, covers the creation of MainMenu Scene, explains Options Scene, and demonstrates how to transition between the scenes in the game.
Chapter 7, Gamestats, Social, IAP and Ad integration, demonstrates how to save in-game progress, add social media integration such as Facebook and Twitter, ad integration, and In-App purchases to add monetization.
Chapter 8, Sound, Finishing Touches, and Publishing, lets us add finishing touches to the game and add sound. We will see how to run the game on the device and publish the game to the Android Play Store.
You will need the latest version of Unity, which you can download from their website, and a computer that can run Unity. A basic understanding of C# is required as the code in this book is written in C#. Although the game can run on an Android emulator, to see the actual performance of the game, an Android device would be required.
This book is geared toward novice or intermediate Unity3D developers who want to expand their knowledge of Unity3D and create high-end, complex Android games. You are expected to have a basic or intermediate understanding of Unity3D, working with its environment, basic concepts such as Game Objects and Prefabs, Unity Scripting using C# or JavaScript, and how to develop basic 2D/3D games using Unity3D.
The book is very useful for those Unity developers who have created basic/simple games for Android and want to learn the ins and outs and core components of high-end complex games that have features such as detailed animations, multiple levels, character abilities, enemy weaknesses, intelligent AI, achievements, leaderboards, and a lot more.
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 e-mail [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 e-mailed directly to you.
You can download the code files by following these steps:
Log in or register to our website using your e-mail 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-Android-Game-Development-with-Unity. 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 http://www.packtpub.com/sites/default/files/downloads/MasteringAndroidGameDevelopmentwithUnity_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.
In today's era of smartphones, which once was the era of computers, almost everyone on the planet is holding a smartphone in their hands. About 1 billion Android phones have been sold in 2014, which is a huge audience for developers who work on Android. These developers put their effort into creating high utility apps, which solves the problems of their users or addicting and fun games and allows players to pass the time having fun and enjoying good interactive experiences. This book is mainly focused on covering the latter part, creating addictive fun games, by using a very famous game engine called Unity3D.
This chapter includes the following topics.
Introduction to Android
Unity3D and Game Engines
Basics of Unity Game Development
Configuration of Empty Game Projects
Starting the Perky Penguin Game
Adding the Penguin to the Game
Android is a Linux-based operating system, which makes it open source software distributed under the Apache License Agreement by Google Inc. Due to its open source nature, other phone vendors have started porting the Android operating system on their newly created phones, which contributed to a very varied smartphone market for consumers. Starting from the first version of Android, this operating system has gained a good level of maturity, making it more reliable, secure, and stable operating system for smartphones. Let's have a look on some popular versions of Android in the next section.
Year by year, Android has increased its maturity level with each new version. Every version introduced new set of features from the user interface to customizations to flexibility to security. In terms of names, these versions are based on names of candy, chocolates, and other sweet stuff, such as Kitkat, Lollipop, and Marshmallow, but that's what makes Android a little more understandable to consumers and developers as well.
The following table highlights the main features of the different Android versions with their API levels as well:
Android version
Version name
Main features
API level
Release month
1.0 G1
Banana Bread
GPS, Bluetooth, Multitasking, Google Services, Android Play Store
2
February 2008
1.5
Cupcake
Search Box, Revamped Android Play Store, Camera, Gestures
3
April 2009
1.6
Donut
Onscreen Keyboard, Home Screen Widgets, Folders
4
September 2009
2.0.x
Éclair
Multiple User Accounts, Flash Support, Zoom Feature, Bluetooth 2.1
5, 6, and 7
October 2009
2.2.x
Froyo
USB tethering, Hotspot support, Adobe Flash, Voice Dialling
8
May 2010
2.3.x
Gingerbread
New Copy/Paste, WebM, NFC, Front Camera
9, 10
December 2010
3.x
Honeycomb
3D Graphics, Redesigned UI, Video Chatting, Bluetooth tethering, 3G, 4G
11, 12, and 13
February 2011
4.0.x
Ice Cream Sandwich
Virtual buttons, Face Unlock, Native Camera Features, Face Detection, Android Beam, Wi-Fi Direct
14 and 15
October 2011
4.1 - 4.3
Jelly Bean
Expandable Notifications, Google Now
16, 17, and 18
July 2012
4.4
Kit Kat
Major Design Interface Update, Translucent Status bar, Immersive Mode, Wireless Printing
19 and 20
October 2013
5.0
Lollipop
Redesigned UI with Material, Lock Screen Notifications, Guest mode, Battery Saver mode
21
October 2014
6.0
Marshmellow
Fingerprint security support, Doze mode for battery saving, App standby mode, Enhanced App permission
23
October 5, 2015
7.0
Nougat
Multi window view, VR support
24, and 25
August 22, 2016
The table only shows the changes made by Android operating system's developer, Google Inc. But due to Android's open source nature, other mobile manufacturing companies have also changed and introduced new features and modifications into Android. For example, Samsung has made a custom touch interface called TouchWiz, and HTC has made a custom user interface called HTC Sense. Similarly, Sony has introduced a custom user interface called TimeScape.
After the introduction of smart phones, the concept of market store came to existence in software technology, which revolutionized the mobile development industry. A significant role was played by Google Play in that revolution of mobile apps and games. Google Play is the largest market store in smartphones, with more than 2.2 million Android apps, games, books, music, shows, and more. These apps and games have been downloaded more than 50 billion times up to this point, and that marks a huge milestone achieved by Google in just 8 years of Android. You can check out Google Play at http://play.google.com.
A game engine is a software framework designed for the creation and development of video games. Many tools and frameworks are available for game designers and developers to code a game quickly and easily without building from the ground up. As time passed by, game engines have become more mature and easy for developers, with feature-rich environments. Starting from native code frameworks for Android such as Unity, Unreal, Cocos2D-x, LibGDX , and so on, the game engines started providing clean user interfaces and drag-drop functionalities to make game development easier for developers. These engines include lots of the tools which are different in user interface, features, porting, and many more things but all have one thing in common; that is they create video games at the end.
We will discuss some of the most popular game engines in this section by comparing those on the basis of:
User Interface and environment like how easy it is to learn and develop games.
Features and functionality like what game engine can achieve and do and on what level of quality.
Pricing like is it free or paid.
Let's get into more details with this comparison.
Unreal Engine (http://www.unrealengine.com) is a game engine developed by Epic Games. It was an in-house game engine of Epic Games and was first showcased in 1998 first person shooter game Unreal. Unreal Engine is mostly used for creating first-person or third-person shooter games but it has also shown quite good quality in other genres such as stealth, MMORPGs etc. Unreal Engine includes high degree of portability and easy interface features with more logic and behaviors written in C++ language.
The latest release called as Unreal Engine 4 supports almost all platforms supported by Unity including Windows, Xbox One, Windows RT, OS X, Linux, PlayStation 4, iOS, Android, Ouya, and browsers using WebGL.
Unreal Engine 4 was released in March 2014 for the public use. Unreal Engine has nice user interface and navigation controls are very polished and easy to use. Unreal Engine provides very easy flow and interface to create first person shooter games and contains features to produce AAA quality game including real-time global illumination using voxel cone tracing, eliminating pre-computed lighting.
You can download the engine and use it for everything from game development, education, architecture, and visualization to VR, film and animation. When you ship a game or application, you pay a 5% royalty on gross revenue after the first $3,000 per product, per quarter Unreal Engine's learning curve is a little high so it's not best suited for new aspiring game developers:
Adobe Flash (formerly called as Macromedia Flash) (http://www.adobe.com
