Unity 5 for Android Essentials - Valera Cogut - E-Book

Unity 5 for Android Essentials E-Book

Valera Cogut

0,0
23,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Unity is a very popular and effective technology for creating 2D and 3D games and applications. The Unity rendering engine provides great real-time rendering of high quality graphics without too much cost and effort. It boasts industry leading multi-platform support and world class monetization and retention services for mobile games, making it the first choice for many game developers across the world. Unity 5 is a great starting point for game developers looking to develop stunning and robust games.
Starting with a refresher on the basics of Unity 5, this book will take you all the way through to creating your first custom game. By the end of the book, you will understand how to work with all the aspects of Unity 5. You will quickly explore all the major key features of the Unity 5 engine and learn to implement real-world Android game and application features in practice.
We begin by introducing how to set up the Android SDK on Windows and Mac OS X and configure Unity 5 settings for the Android platform. As you progress through the chapters, you will learn to implement innovative and user-friendly features with the aid of real-world examples. You will explore how to render high quality graphics with physically-based shaders and global illumination to enhance your project’s performance. Building on this, you will then learn to transform your native C# and JavaScript code into Unity scripts. Best practices to improve your Android games will also be discussed to help you create games fast and efficiently. Finally, putting together all these concepts, you will learn to create your own Android game from scratch.
This book will teach you how to harness the benefits of different tools to become proficient at game design and development processes.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 208

Veröffentlichungsjahr: 2015

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Unity 5 for Android Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
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
Errata
Piracy
Questions
1. Setting Up and Configuring an Android Platform
Configuring Unity 5 for Android devices
APK expansion files in Unity 5
Overview
Formats
The updating process
Setting up expansion files in Unity 5
Building for Android devices
Unity License Comparison Overview
NavMeshes, pathfinding, and crowd simulation
Level of Detail (LOD) support
Audio filters
Video playback and streaming
Full-fledged streaming with asset bundles
Hundred thousand dollar turnover
Mecanim – IK Rigs
Mecanim – sync layers and additional curves
Custom splash screen
Build size stripping
Lightmapping with global illumination and area lights
HDR and tone mapping
Occlusion culling
Light probes
Static batching
Render-to-texture effects
Fullscreen postprocessing effects
NavMesh – dynamic obstacles and priority
.NET socket support
Profiler and GPU profiling
Real-time directional shadows
Script access to asset pipeline
Summary
2. Accessing Android Functionality
Creating Java and native C plugins for an Android platform
Creating plugins in C
Creating plugins in Java (Eclipse IDE)
Writing Java code in plugin
Turning on and off a hardware flashlight
On Unity side
Exporting and importing a JAR library from Eclipse into Unity
Importing AndroidManifest
Using Java plugins in Unity scripts
Anti-piracy check
Vibration
Activity Indicator
Screen orientation
System information
Accessing the Android sensors and features within Unity 5
Acceleration
Gyroscope
Compass
Summary
3. High-end Graphics for Android Devices
Physically-based shaders
Basic shader concepts
The vertex shader
The geometry shader
The pixel/fragment shader
Shading languages
Cg
Unity shaders in Cg
A custom diffuse lighting model
A basic reflection environment
Masked texture reflection
Lighting model techniques
The Lit sphere model
Realistic rendering
Global illumination
Practicing in shader optimization
Best case practice
Summary
4. Animation, Audio, Physics, and Particle Systems in Unity 5
New Mecanim animation features in Unity 5
State machine behavior
State machine transition
Asset creation API
Direct blend tree
Programmatically creating assets by Unity 5 API
Creating the controller
Adding parameters
Adding state machines
Adding states
Adding transitions
Going deeper into new audio features
Mood transitions
Physics and particle system effects in Unity 5
Particle system performance tips and tricks
Legacy versus Shuriken Unity's built-in particle systems
Particle system tips
Summary
5. Asset Bundles in Unity 5 Pro
An overview of the asset bundles in Unity 5
Downloading new code and data in real time for Android devices
Managing loaded asset bundles
Asset bundles and binary data
Asset bundles and scripts
Asset bundle dependencies
Safeness techniques in practice
Summary
6. Optimization and Transformation Techniques
Occlusion culling and level of detail in optimization techniques
Optimizing by LOD
Unity C# and Unity JS optimization tips and tricks
Transforming Unity C# code into Unity JavaScript code and vice versa
JavaScript variables and types
C# variables and types
Converting types in Unity JS
Converting types in Unity C#
Unity JS function versus Unity C# function
Unity JS return versus Unity C# return
Unity JS yielding versus Unity C# yielding
Unity JS directives versus Unity C# directives
Summary
7. Troubleshooting and Best Practices
Measuring performance with the built-in Android profiler
General CPU activity
Rendering statistics
Detailed Unity player statistics
Detailed script statistics
Detailed statistics on memory allocated by scripts
Debugging Android devices with the Unity profiler tool
Profiler timeline
The CPU area
The Rendering area
The Memory area
The simple view
The detailed view
The audio area
The physics area
The GPU area
Real-practice techniques
The high-speed, off-screen particles technique in Unity
The pool technique
The scriptable profiler tool
Unity profiler tricks
Creating a simple profiler
Summary
Index

Unity 5 for Android Essentials

Unity 5 for Android Essentials

Copyright © 2015 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, 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: August 2015

Production reference: 1310715

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78439-919-1

www.packtpub.com

Credits

Author

Valera Cogut

Reviewers

Todd Bello

Robbyn Blumenschein

Ali Raza

Joe Whitehouse

Commissioning Editor

Amarabha Banerjee

Acquisition Editor

Vinay Argekar

Content Development Editor

Samantha Gonsalves

Technical Editor

Faisal Siddiqui

Copy Editor

Charlotte Carneiro

Project Coordinator

Kinjal Bari

Proofreader

Safis Editing

Indexer

Tejal Soni

Production Coordinator

Aparna Bhagat

Cover Work

Aparna Bhagat

About the Author

Valera Cogut is an independent professional software and video game developer who has worked in the game industry since 2008 and has more than 12 years of programming experience. He is a passionate software and game developer with different areas of expertise. Before diving into the game industry 6 years ago, Valera created websites and applications with PHP, the Yii framework, the Zend framework, Relational Database Management Systems, Apache and Nginx, C#, C++, C, Objective-C, Java, Python, UML, and many other technologies. Having a mathematical background (analytical geometry, linear algebra, logic, statistics and probability, differential equations, graph theory, and mathematical analysis), he finally realized that game development was his mission. Reusable designs, optimized algorithms, clean code, and elaborated workflows—these things make him happy.

Valera has had the opportunity to produce titles for multiple platforms, including Windows Phone, Android, iOS, PC, and Mac. Today, he continues to produce fun and original games, participate in game jams, and author books. He was a technical reviewer for Unity Android Game Development by Example Beginner's Guide, Packt Publishing.

Currently, Valera has a contract as a Unity3D C# developer for Kaufcom GmbH, a well-known games and apps producer from Switzerland http://www.kauf.com (Android games: https://play.google.com/store/search?q=kaufcom).

First of all, thanks to Vinay Argekar, Melita Lobo, Samantha Gonsalves, and the Packt Publishing team for creating this book plus many others, thereby helping the Unity community grow and mature. A special thanks goes to my family for the love, education, and freedom they gave me. I would also like to thank my best friends, Paul Kofmann, Alexander Kofmann, and Vitaly Shapovalov. Thanks to the Kaufcom company. Of course, no progress of mine could have been achieved without the support and love of my wife, Irina.

About the Reviewers

Todd Bello is a software engineer at Microsoft working on 3D Maps for Bing and Windows. He graduated from Rochester Institute of Technology in 2013 with a BS in game design and development. He has reviewed a few MSDN articles and the free e-book Machine Learning Using C# Succinctly by James McCaffery.

I'd like to thank my friend Leigh Raze.

Robbyn Blumenschein comes from a humble background. She was raised in a military family. Then, she joined the military, but she has always been interested in creating games. She worked for Cryptic Studios, Electronic Arts, I-Play, Kunomi, Aeria Games, and finally, started her own business, 2 Bee Soft LLC.

I always think about my mentor and teacher, Patrick Downey, who passed away in 2007. I will never give up on my dream.

Ali Raza has over 8 years of international industry experience working with companies from US, UK, Australia, Norway, and Brazil in almost every major field of design and development. He has developed applications and games for Windows, Mac, iOS, Android, BlackBerry, and web platforms. He has been a part of social networks, healthcare IT, gaming, industrial automation, business and finance, media, and e-learning, which have enabled him to grow into a versatile developer with a diverse skill set.

He is currently working as a UI/UX program development lead architect in a US-based healthcare IT company, which specializes in cross-platform IT healthcare products.

In addition to that, Ali is also the founder of a start-up company, where he works with the aid of a self-trained team on various cross-platform applications for international clientele in Norway, Brazil, and Italy.

Ali is an Adobe Training Partner and Microsoft Certified Trainer in enterprise, desktop, and web development. He has held several nationwide exclusive official and custom-based training camps on core design methodologies and programming languages at companies, universities, and government organizations.

Ali is a published author and has contributed to key international magazines, books, and examination aides in a wide area of IT topics, including gaming, data visualization, and web technologies. He has authored dozens of articles for Flash & Flex Developer Magazines, Software Development Journal, and Packt Publishing.

Furthermore, Ali also technically reviews IT-based books and publications from time to time.

You can reach him at <[email protected]>.

I would like to thank Melita Lobo and Kinjal Bari from Packt Publishing for giving me the opportunity to be part of the technical reviewing team. I am also indebted to my long time friend, Sadia Suhail, who helped me with the reviewing process.

Thank you! God bless you all!

Joe Whitehouse has been playing video games since he was a very young child. Growing up, he became more and more fascinated with how they worked or could be broken down. For years, he enjoyed searching for exploits and was one of those to discover the Halo Super Bounce. Many years later, this curiosity and interest in breaking games led to triOS College's video game design and development course. Here, he was taught by Christopher Coey and graduated with distinction. During his time at triOS College, Joe interned at a gaming studio, Little Guy Games, working as a programmer but took on more of a role as a technical tester, finding and fixing bugs. He has also created many video game prototypes using XNA, Unity 2D and 3D, Android, and HTML5 Games.

More recently, he went back to triOS college for their video game design technologies, a course taught by Rocco Commisso. Joe is now learning to create all the visuals in video games so that he can reach another goal: to create more games outside of school with a small team.

I would like to thank Christopher Coey for teaching the programming course and putting up with all my many questions at the start. I would also like to thank Rocco Commisso for everything he taught me as I continue to learn.

www.PacktPub.com

Support files, eBooks, discount offers, and more

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.com and 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://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Free access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.

Preface

Learn the Unity 5 engine to master designing and building awesome real-world games and applications for Android devices. Design beautiful effects, animations, physical behaviors, and other different real-world features and techniques for your Android games and applications. Optimize your project and any other real-world projects for Android devices. Know more in practice about accessing Android functionality, rendering high-end graphics, expanding your project using asset bundles, and of course learn about deploying on the Android platform and much more.

Unity is essentially a development environment for multiple platforms (Android, iOS, Blackberry, Windows Phone, Windows, Playstation, Xbox, Mac, Linux, and Web). Unity is a very popular and effective technology for creating 2D and 3D games and applications. This technology provides many useful and effective tools to solve various issues. The Unity rendering engine provides great real-time rendering of high-quality graphics without too much cost and effort.

The Android platform and game industry is developing like never before. Most programmers using Unity, especially those new to the technology, would like to learn to recreate different functional parts from the most popular real-world games and applications that will cause a great concern in the community.

Whether you are new to Unity 5 or an expert, this book will provide you with the required skills you need to successfully design, implement, build, and enhance the quality of your Android game or application. By sequentially working through the steps in each chapter, you will quickly master the key features of the Unity 5 engine to implement real-world Android games and application features in practice.

This book is aimed for competent Unity developers who want to learn to develop, optimize, and publish games for Android devices. Know more about the Unity 5 engine to build awesome real-world Android games.

Starting from the beginning, this book will explain the configuration of the Unity 5 settings for the Android platform. Implement the innovative and user-friendly features using real-world techniques and tips and tricks in practice. Explore how to improve your Android games and enhance its performance. Open a wonderful world of rendering high-quality graphics with physically-based shaders and global illumination. Discover Android features inside the Unity 5 engine and more about transformation from native C# and JavaScript codes into Unity scripts.

This book is aimed at covering the fundamentals relating to typical real-world games and applications and to explore a basic overview of the concepts but the focus is on providing the practical skills required to develop Android games and applications.

Unity 5 for Android Essentials will teach you to use different tools provided by the Unity Technologies team in order to master your game's design and development processes. This book will be a practical guidebook that will help you to leverage the Unity 5 framework in order to build awesome games and apps for Android devices.

What this book covers

Chapter 1, Setting Up and Configuring an Android Platform, explains how to configure Unity 5 for Android devices. Also in this chapter, we will explore about APK expansion files in Unity 5. At the end of the chapter, you will build a very simple and basic game example for Android devices.

Chapter 2, Accessing Android Functionality, covers how to create plugins for the Android platform using Java and C languages in Unity 5. The reader will learn in practice how to write simple plugins for the Android platform. Also, the reader will learn to make anti-piracy checks, detect screen orientation, handle vibration support, determine device generation, and do more useful things.

Chapter 3, High-end Graphics for Android Devices, primarily explores how to enhance the quality in games and applications using physically-based shaders. This chapter will also describe global illumination in Unity 5. At the end of the chapter, you will optimize a shader code.

Chapter 4, Animation, Audio, Physics, and Particle Systems in Unity 5,will cover new Mecanim animation features in Unity 5. After that, you will learn awesome new audio features in Unity 5. At the end of this chapter, you will explore physics and particle systems in Unity 5.

Chapter 5, Asset Bundles in Unity 5 Pro, includes an overview of asset bundles in Unity 5. You will learn to download new code and data in real time for Android devices. At the end of this chapter, you will discover the safety technique of the asset bundles in practice.

Chapter 6, Optimization and Transformation Techniques, introduces the usage of occlusion culling and optimization techniques for the level of detail. You will learn to optimize Unity C# and Unity JS code. Finally, you will see how to transform Unity C# code to Unity JavaScript code and vice versa.

Chapter 7, Troubleshooting and Best Practices, covers the optimization of any game for Android devices and teaches you to find any bottlenecks. In this chapter, you will discover some troubleshooting techniques for the Android platform. At the end of this chapter, you will learn the best practices that are used by many professionals from all over the world for their scripts and shaders.

The online chapter, Developing Glow Hockey from Scratch, shows you how easy it is to develop the most popular game in the Android Market (Glow Hockey has about 100,000,000–500,000,000 installs https://play.google.com/store/apps/details?id=com.natenai.glowhockey&hl=en) in Unity 5 from scratch. Also, you will learn to optimize your project and any other real-world projects for Android devices. Many more useful details and features will be covered in this chapter. You can find this chapter at https://www.packtpub.com/sites/default/files/downloads/9191OT_BonusChapter.pdf.

What you need for this book

You need the following software for this book:

Windows or Mac OS XJava Development Kit (JDK)Android SDKUnity3D

Who this book is for

This book is for readers that have a basic knowledge of the architecture of Unity, programming plus shading, and for those who are expert Unity developers. This book is very helpful for anybody who wants quick solutions and answers for many different questions and issues while developing a game or application in Unity.

Perhaps you already know a bit about the Unity 5 engine, but have never used it before; or perhaps, you know programming but are new to using Unity 5 to develop Android games and applications. In all cases, this book will quickly teach you to master high-quality Android games and applications. This book is for anyone who wants to explore a wide range of Unity features and finds ready-to-use techniques, solutions, tips and tricks that are used all over the world. It is best for you if you have basic experience with C# or JavaScript and feel comfortable enough with the Unity workflow.

Whether you've developed games before or not, and you're just looking to get started in Unity to make new fantastic real-world games and applications, this book will help you. This book is for you and everyone in your team, from beginners to expert developers!

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

using UnityEngine; public class YourClassName: MonoBehaviour { void OnCollisionExit (Collision collision) { Debug.Log ("OnCollisionExit :" + collision.gameObject.name); } }

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

using UnityEngine; public class YourClassName: MonoBehaviour { void OnCollisionExit (Collision collision) { Debug.Log ("OnCollisionExit :" + collision.gameObject.name); } }

Any command-line input or output is written as follows:

# cp /usr/src/asterisk-addons/configs/cdr_mysql.conf.sample /etc/asterisk/cdr_mysql.conf

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Clicking on the Next button moves you to the next screen."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title via 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 on www.packtpub.com/authors.

Customer support

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.

Downloading the example code

You can download the example code files for all Packt books you have purchased 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.

Errata

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 would 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 on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright 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.

Questions

You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.

Chapter 1. Setting Up and Configuring an Android Platform

This chapter will talk about installing the Android SDK on Windows and Mac OS X platforms. Further, the reader will find how to configure Unity 5 for Android devices. Also, in this chapter, we will explore the APK expansion files in Unity 5. In this chapter, the reader will build the Glow Hockey project (we will create this game in Unity 5 from scratch in the last chapter in this book) on an Android device. At the end of this chapter, the reader will explore the side-by-side comparisons of the Unity Pro and Unity Basic-specific features and rules.

The topics that will be covered in this chapter are as follows:

Configuring Unity 5 for Android devicesAPK expansion files in Unity 5Building for Android devicesUnity license comparison overview

Configuring Unity 5 for Android devices

Once you have installed the Android SDK and set up Unity, you must configure the correct settings for each of your Android project. We will begin our review by considering the Resolution And Presentation options as shown in the following screenshot. In order to access the Android platform settings in Unity, it is necessary to navigate to the Edit | Project Settings | Player menu and then click on the button with the Android icon. Also, the other way of getting to the Android platform settings is by navigating to File | Build Settings. After opening the window, you will need to click on the Player Settings button at the bottom.

The Default Orientation option is shared between multiple mobile platforms. This setting is necessary in order to indicate the orientation of the screen which is designed for your game or your application. The default is Automatic Rotation for all settings. If, for example, your project is designed only for the portrait orientation of the screen, then you need to select either the Portrait or Portrait Upside Down value:

We can pick one of the following properties: Portrait, Portrait Upside Down, Landscape Right, Landscape Left, and Auto Rotation. They are