Unity 2021 Cookbook
eBook - ePub

Unity 2021 Cookbook

Over 140 recipes to take your Unity game development skills to the next level, 4th Edition

Matt Smith, Shaun Ferns

Buch teilen
  1. 816 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Unity 2021 Cookbook

Over 140 recipes to take your Unity game development skills to the next level, 4th Edition

Matt Smith, Shaun Ferns

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

Discover the latest features of Unity 2021 and dive deeper into the nuances of professional game development with Unity

Key Features

  • Discover the latest features of Unity 2021 including coverage of AR/VR development
  • Follow practical recipes for better 2D and 2D character development with Unity GameKits
  • Learn powerful techniques and expert best practices in building 3D objects, textures, and materials

Book Description

If you are a Unity developer looking to explore the newest features of Unity 2021 and recipes for advanced challenges, then this fourth edition of Unity Cookbook is here to help you.

With this cookbook, you'll work through a wide variety of recipes that will help you use the essential features of the Unity game engine to their fullest potential. You familiarize yourself with shaders and Shader Graph before exploring animation features to enhance your skills in building games.

As you progress, you will gain insights into Unity's latest editor, which will help you in laying out scenes, tweaking existing apps, and building custom tools for augmented reality and virtual reality (AR/VR) experiences. The book will also guide you through many Unity C# gameplay scripting techniques, teaching you how to communicate with database-driven websites and process XML and JSON data files.

By the end of this Unity book, you will have gained a comprehensive understanding of Unity game development and built your development skills. The easy-to-follow recipes will earn a permanent place on your bookshelf for reference and help you build better games that stay true to your vision.

What you will learn

  • Discover how to add core game features to your projects with C# scripting
  • Create powerful and stylish UI with Unity's UI system, including power bars, radars, and button-driven scene changes
  • Work with essential audio features, including background music and sound effects
  • Discover Cinemachine in Unity to intelligently control camera movements
  • Add visual effects such as smoke and explosions by creating and customizing particle systems
  • Understand how to build your own Shaders with the Shader Graph tool

Who this book is for

If you're a Unity developer looking for better ways to resolve common recurring problems with recipes, then this book is for you. Programmers dipping their toes into multimedia features for the first time will also find this book useful. Before you get started with this Unity engine book, you'll need a solid understanding of Unity's functionality and experience with programming in C#.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Unity 2021 Cookbook als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Unity 2021 Cookbook von Matt Smith, Shaun Ferns im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Programming in C#. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
2021
ISBN
9781839219276
Advanced Topics - Gizmos, Automated Testing, and More
This chapter will put together four sets of advanced recipes:
  • Gizmos
  • Saving and loading game data
  • Automated testing
  • An introduction to Unity Python
Let's take a look at each in this introduction!
Gizmos
Gizmos are another kind of Unity editor customization. Gizmos are visual aids for game designers that are provided in the Scene window. They can be useful as setup aids (to help us know what we are doing) or for debugging (understanding why objects aren't behaving as expected).
Gizmos are not drawn through Editor scripts, but as part of the Monobehaviour class, so they only work for GameObjects in the current scene. Gizmo drawing is usually performed in two methods:
  • OnDrawGizmos(): This is executed every frame or editor window repaint, for every GameObject in the Hierarchy window.
  • OnDrawGizmosSelect(): This is executed every frame, for just the/those GameObject(s) that are currently selected in the Hierarchy window.
Gizmo graphical drawing makes it simple to draw lines, cubes, and spheres. More complex shapes can also be drawn with meshes, and you can also display 2D image icons (located in the Project folder: Assets | Gizmos).
Several recipes in this chapter will illustrate how Gizmos can be useful. Often, new GameObjects created from editor extensions will have helpful Gizmos associated with them.
Saving/loading data at runtime
When loading/saving data, it is important to keep in mind the data types that can be used. When writing C# code, our variables can be of any type permitted by the language, but when communicated by the web interface, or to local storage using Unity's PlayerPrefs class, we are restricted in the types of data that we can work with. When using the PlayerPrefs class, we are limited to saving and loading integers, floats, and strings. We will provide several recipes illustrating ways to save and load data at runtime, including the use of static variables, PlayerPrefs, and a public class called TextAsset containing text-format data for a 2D game level.
PlayerPrefs offers a great, cross-platform way to store persistent data locally for Unity games. However, it is also very easy to hack into, so sensitive or confidential data should not be stored using this technique. For securely storing data online in hashed/encrypted format, data storage methods should be used. But for data such as lives left, checkpoints reached, scores and time remaining, and so on, it is an easy and simple way to implement memory after a scene has been exited.
Automated testing
For a very simple computer program, we can write code, run it, enter a variety of valid and invalid data, and see whether the program behaves as we expect it to. This is known as a code-then-test approach. However, this approach has several significant weaknesses:
  • Each time we change the code, as well as run new tests relating to the code we are improving, we have to run all the old tests to ensure that no unexpected modified behaviors have been introduced (in other words, our new code has not broken another part of our program)
  • Running tests manually is time-consuming.
  • We are relying on a human to rerun the test each time. However, this test may be run using different data, some data may be omitted, or different team members may take a different approach to run tests.
Therefore, even for simple programs (and most are not simple), some kind of fast, automated testing system makes a lot of sense.
There is an approach to software development called test-driven development (TDD), whereby code is only written until all tests pass. So, if we want to add or improve the behavior of our game program, we must specify what we want in terms of tests, and then the programmers write code to pass the tests. This avoids a situation whereby programmers write code and features that are not needed, spend time over-optimizing things that would have been fine, and so on. This means that the game development team directs its work toward agreed goals understood by all since they have been specified as tests.
The following diagram illustrates the basic TDD in that we only write code until all tests pass. Then, it's time to write more tests:
Figure 13.1 – Test then code to the test
Another way that TDD is often summarized is as red-green-refactor:
  • Red: We write a new test for which code is needed, so initially, our test fails (in other words, we write a test for the new feature/improved behavior we wish to add to our system).
  • Green: We write code that passes the new test (and all the existing ones).
  • Refactor: We (may...

Inhaltsverzeichnis