39,59 €
Understand what makes Unity the world’s most widely used real-time 3D development platform and explore its powerful features for creating 3D and 2D games, as well as the Unity game engine and the Microsoft Game Dev, including the Microsoft Azure Cloud and Microsoft Azure PlayFab services, to create games.
You will start by getting acquainted with the Unity editor and the basic concepts of Unity script programming with C#. You'll then learn how to use C# code to work with Unity's built-in modules, such as UI, animation, physics, video, and audio, and understand how to develop a game with Unity and C#. As you progress through the chapters, you'll cover advanced topics such as the math involved in computer graphics and how to create a custom render pipeline in Unity with the new Scriptable Render Pipeline, all while optimizing performance in Unity. Along the way, you'll be introduced to Microsoft Game Dev, Azure services, and Azure PlayFab, and using the Unity3D PlayFab SDK to access the PlayFab API.
By the end of this Unity book, you'll have become familiar with the Unity engine and be ready to develop your own games while also addressing the performance issues that you could encounter in the development process.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 396
Veröffentlichungsjahr: 2022
The ultimate guide to creating games with Unity and Microsoft Game Stack
Jiadong Chen
BIRMINGHAM—MUMBAI
Copyright © 2022 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.
Group Product Manager: Pavan Ramchandani
Publishing Product Manager: Aaron Tanna
Senior Editor: Aamir Ahmed
Content Development Editor: Feza Shaikh
Technical Editor: Joseph Aloocaran
Copy Editor: Safis Editing
Project Coordinator: Manthan Patel
Proofreader: Safis Editing
Indexer: Tejal Daruwale Soni
Production Designer: Aparna Bhagat
Marketing Coordinator: Anamika Singh
First published: May 2022
Production reference: 2130522
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-80107-807-8
www.packt.com
This book is dedicated to my wife, Yi Liang, for her encouragement and support, especially during the COVID-19 pandemic; her positive attitude toward life has inspired me and helped me through difficult times.
– Jiadong Chen
"A delayed game is eventually good, but a rushed game is forever bad."
– Industry catchphrase
You now hold in your hands the tools to make great games. If this was a Mario game, then you just punched a question mark block, and then a glowing, flashing, smoking mushroom just rose out of it. If this was a Zelda game, then you just navigated a boss dungeon, found a treasure chest, pulled this book out of it, and raised the book high above your head (with some suitable music playing). In other words, you just acquired a key powerup for your quest.
You can feel that dedication to excellence (which the industry quote refers to) when you play Nintendo games, Halo, Minecraft, and Sonic the Hedgehog (and pretty much whatever your favorite game is). Now you have the same opportunity: you can use your knowledge and your new Unity skills (granted, you probably haven't learned them yet) to make a powerful statement through your work.
"Nintendo's philosophy is to never go the easy path; it's always to challenge ourselves and try to do something new."
– Shigeru Miyamoto (2005)
So that's why Nintendo makes some great games (and some really weird ones)! Regardless, here's your chance to make something that's unique and that really shows who you are. With these tools, your passion opens limitless opportunities.
And that brings us to a Microsoft quote (you knew it was coming).
"Learning to fly is not pretty, but flying is."
– Satya Nadella, Hit Refresh
You learn tools to create masterpieces (or to at least get a job, or a better one). It's not easy to learn these new tools, but after you gain this knowledge, you can make great games.
Game Development with Unity for .NET Developers makes that process a whole lot easier! Unity is the world's most widely used, real-time 3D development platform for a reason! If you approach Unity with the .NET Framework, then you can leverage the power of C#, Microsoft Game Dev tools, Microsoft Azure Cloud services, and Azure PlayFab. You'll also see how these resources work seamlessly with Visual Studio and GitHub.
Our author, Jiadong Chen, used to work at Unity Technologies as a field engineer. He's been working in this .NET and Unity gaming stack for over 9 years. He's a member of the .NET Foundation, and has been a Microsoft MVP (Most Valuable Professional) for 6 years. (That means he's been awarded the title every year since 2015, based on his impact on the Microsoft developer community.) As you can imagine, his MVP award category is Developer Technologies. In other words, Jiadong is the perfect person to teach you how to use the .NET Framework and Microsoft developer stack to learn how to develop with the Unity game engine and how to take your games to the next level!
Make no mistake: as the title implies, this is a book for .NET developers to learn Unity. First, Jiadong starts with the basics of the Unity game engine. Then, you'll dig into scripting, using Unity to build your game UI, animating your game graphics, building physics, and adding audio and video (the basic components of building your game). Next, Jiadong gets into game math, while also using a rendering pipeline, data-oriented tech, a serialization system, and assets management. Finally, he shows you how to leverage the Microsoft Game Dev suite of technologies, Azure Cloud, and Azure PlayFab as you develop with the Unity engine.
In Game Development with Unity for .NET Developers, Jiadong Chen takes you on a tour, explaining the concepts with images and examples, so that you can fully understand each topic. He then takes you through the process, using real code, so that you can implement your own solutions. The process of learning how to develop games isn't easy, but this book will make it a lot easier.
After you're done reading the book, if life was a Mario game, you'll have grabbed the flag at the top of the flag pole and entered a sewer pipe! If this was a Zelda game, you'll have collected the Triforce. And if it's a Sonic game, then you just beat Dr. Robotnik in a giant robot mech that looks like him. As Satya Nadella implied, learning to fly won't be easy, but once you're done, you're going to be able to really take off and do some great things with Unity!
Ed Price
Senior Program Manager of Architectural Publishing
Microsoft, Azure Architecture Center (http://aka.ms/Architecture) Co-author of seven books, including Meg the Mechanical Engineer, The Azure Cloud Native Architecture Mapbook (Packt), and ASP.NET Core 5 for Beginners (Packt)
Jiadong Chen is one of 3,000 international Microsoft® Most Valuable Professional (MVP) award winners, recognized by Microsoft as one of the technology industry's best and brightest six years in a row, and is currently working as a senior software developer at Company-X, based in Hamilton, New Zealand.
He specializes in the Microsoft Azure cloud, Unity and XR development, and .NET/C#. He is a Microsoft Certified Azure Solutions Architect Expert, a Microsoft Certified Azure Developer, a Microsoft Certified Azure AI Engineer, and a Microsoft Certified Trainer. He is also a member of the .NET Foundation.
Before joining Company-X, Jiadong worked for Unity, the creator of the world's most widely used real-time 3D development platform, as a field engineer.
After this long adventure, I would first like to thank my wife for her support. Writing a book is not an easy task, especially during the COVID-19 pandemic, and my wife's support has given me the psychological comfort to overcome the difficulties and finish the book.
A special thanks to the Packt team (especially Aaron, Manthan, and Feza) for being with me on this journey.
Simon Jackson is a long-time software engineer and architect with many years of Unity game development experience, as well as an author of several Unity game development titles. He loves to both create Unity projects and lend a hand to help educate others, whether it's via a blog, vlog, user group, or major speaking event.
He currently works at a mixed-reality research lab called xRealityLabs, building the future of digital solutions for the construction and medical industries.
His primary focus at the moment is on the Reality Toolkit project, which is aimed at building a cross-platform mixed-reality framework to enable both VR and AR developers to build efficient solutions in Unity.
As one of the most widely used game engines in the world, Unity provides easy-to-use and powerful game development tools, which undoubtedly attracts many developers to choose it to develop their own games. However, the tools needed in modern game development are not limited to game engines; other tools and services such as the cloud are increasingly used in game development. In this book, we will explore how to use the Unity game engine and the Microsoft Game Dev, including the Microsoft Azure Cloud and Microsoft Azure PlayFab services, to create games.
Starting by understanding the fundamentals of the Unity game engine, you will gradually become familiar with the Unity Editor and the key concepts of writing Unity scripts in C#, which will get you ready to make your own game.
Then, you'll learn how to work with Unity's built-in modules, such as the UI system, animation system, physics system, and how to integrate video and audio in your game to make your game more interesting.
As you progress through the chapters, I'll take you through advanced topics, such as the math involved in computer graphics, how to create post-processing effects in Unity with the new Scriptable Render Pipeline, how to use Unity's C# Job System to implement multithreading, and how to use Unity's Entity Component System (ECS) to write game logic code in a data-oriented way to improve game performance.
Along the way, you'll also learn about the Microsoft Game Dev, the Azure cloud services, Azure PlayFab, and using the Unity3D PlayFab SDK to access the PlayFab API to save and load data from the cloud.
By the end of this book, you'll be familiar with the Unity game engine, have a high-level understanding of the Azure cloud, and be ready to develop your own games.
The book is for developers with intermediate .NET and C# programming experience who are interested in learning game development with Unity. Basic experience in C# programming is assumed.
Chapter 1, Hello Unity, explains the fundamentals of the Unity game engine. Beginning with the Unity installation process and then exploring the editor, you will also learn about .NET profiles and the scripting backend offered by Unity, and finally, you will have a broad understanding of Unity.
Chapter 2, Scripting Concepts in Unity, continues from the previous chapter and introduces scripting in Unity in detail. It begins by introducing the most commonly used classes in Unity scripting and then explains the life cycle of scripts. It also covers how to create a new script in Unity and attach a script as a component to a GameObject, and demonstrates how to add or remove packages through the Unity Package Manager.
Chapter 3, Developing UI with the Unity UI System, covers the different types of UI elements commonly used in Unity. Additionally, this chapter also discusses how to develop UI in Unity by using a Model View ViewModel (MVVM) architectural pattern. It ends by exploring some optimization tips for Unity UI.
Chapter 4, Creating Animations with the Unity Animation System, covers the most important concepts of the Unity animation system, such as animation clips, Animator Controller, Avatar, and the Animator component. Here, you will implement 3D and 2D animations using the animation system. It ends by exploring some optimization tips for the animation system in Unity.
Chapter 5, Working with the Unity Physics System, presents an overview of the physics solutions provided by Unity, including two built-in physics solutions, the NVIDIA PhysX engine and the Box2D engine. It also covers key concepts in the Unity physics system, such as Collider and Rigidbody. Here, you will implement a physics-based ping-pong game. It ends by exploring some optimization tips for the physics system in Unity.
Chapter 6, Integrating Audio and Video in a Unity Project, covers key concepts in the Unity audio system and video system, such as audio clip assets, Audio Source components, Audio Listener components, and Video Player components. It ends by exploring some optimization tips for the audio system in Unity.
Chapter 7, Understanding the Mathematics of Computer Graphics in Unity, covers the mathematics related to computer graphics, such as coordinate systems, vectors, matrices, and quaternions.
Chapter 8, The Scriptable Render Pipeline in Unity, presents an overview of three ready-made render pipelines to choose from in Unity, namely the legacy built-in render pipeline and two pre-made render pipelines based on the Scriptable Render Pipeline, the Universal Render Pipeline and the High Definition Render Pipeline. It also covers how to use the Universal Render Pipeline Asset to configure the render pipeline and how to use the Volume framework to apply post-processing effects to a game. It ends by exploring some optimization tips for the Universal Render Pipeline.
Chapter 9, Using Data-Oriented Technology Stack in Unity, covers what data-oriented design is and the difference between data-oriented design and traditional object-oriented design. It also explores the Data-Oriented Technology Stack (DOTS) in Unity and the three technology modules that make it up – namely, the C# Job System, ECS, and the Burst compiler.
Chapter 10, Serialization System and Assets Management in Unity and Azure, discusses binary serialization, YAML serialization, and JSON serialization in Unity. It also covers the assets workflow in Unity and ends by exploring how to create an Azure Blob storage service in the Azure cloud and load addressable content from Azure into a Unity project.
Chapter 11, Working with Microsoft Game Dev, Azure Cloud, PlayFab, and Unity, discusses what Microsoft Game Dev, Microsoft Azure Cloud, and Azure PlayFab are and why you should consider using them in game development. Here, you will implement the registration, login, and leaderboard functions in a Unity project through the API of Azure PlayFab.
This book assumes that you have some familiarity with .NET and C#. This book covers basic concepts, advanced topics of the Unity game engine, and also other technologies such as the Microsoft Azure cloud and Azure PlayFab.
You'll also need a Long-Term Support (LTS) version of Unity installed on your computer – 2020 or later is recommended. You can find out how to install Unity on your computer in Chapter 1, Hello Unity. All code examples have been tested with Unity 2020.3.24 on a Windows OS. However, they should work with future version releases too.
You'll also need a Microsoft Azure cloud subscription, and you can apply for a free Azure account at the following link: https://azure.microsoft.com/en-in/free/.
If you wish to download sample projects from our GitHub repository, you will need a Git client; we recommend GitHub Desktop as it is the easiest to use. You can download it at the following link: https://desktop.github.com.
If you are using the Windows OS, you can also consider using Git for Windows. It can be downloaded at the following link: https://git-scm.com/download/win.
If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book's GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Game-Development-with-Unity-for-.NET-Developers. If there's an update to the code, it will be updated on the existing GitHub repository.
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 a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://static.packt-cdn.com/downloads/9781801078078_ColorImages.pdf.
There are a number of text conventions used throughout this book.
Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "If some content is generated at the beginning of the object collision via OnCollisionEnter, and you want to destroy them when the object collision ends, then you should consider using OnCollisionExit."
A block of code is set as follows:
using UnityEngine;
public class TriggerTest : MonoBehaviour
{
private void OnTriggerStay(Collider other)
{
Debug.Log($"{this} stays {other}");
}
}
}
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 PingPongBall : MonoBehaviour
{
[SerializeField] private Rigidbody _rigidbody;
[SerializeField] private Vector3 _initialImpulse;
private void Start()
{
_rigidbody.AddForce(_initialImpulse,
ForceMode.Impulse);
}
}
Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: "Select 3D Object | Plane to create a new Plane object in the editor."
Tips or Important Notes
Appear like this.
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, email us at customercare@packtpub.com and mention the book title in the subject of your message.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packt.com with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Once you've read Game Development with Unity for .NET Developers, we'd love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.
Your review is important to us and the tech community and will help us make sure we're delivering excellent quality content.
In this section of the book, we'll explore the fundamentals of the Unity game engine and introduce some of the key concepts of scripting in Unity to get you ready to make your own games.
This section includes the following chapters:
Chapter 1, Hello UnityChapter 2, Scripting Concepts in UnityBefore we get started with using Unity to develop games, I think it's good to first understand Unity itself. Many people, especially those who are interested in games and game development, know that Unity is a widely used game engine, and you may have played many games developed with Unity. But you may not be familiar with how to use Unity to develop games. For example, there are many different Unity versions available, so how do you choose the version that suits you? Unity provides different subscription plans, but which subscription plan is right for your situation?
If you have never used Unity before, it is necessary for you to learn how to use the Unity Editor first. In addition to the Unity Editor, what features does the Unity engine provide to help game developers develop games? It is also important to know the features in Unity. If you are a .NET developer, then it's likely that you are familiar with Visual Studio. You need to know how to use Visual Studio to develop a Unity game. But developing a Unity game is different from developing a .NET application.
Am I asking too many questions? Don't worry – this chapter will help you answer them.
In this chapter, we will introduce how to choose the right release of Unity and provide an overview of how to download and install Unity via the Unity Hub or the Unity installer. Then, we will choose the right subscription plan for your situation. At this point, you should have installed Unity and opened the Unity Editor.
If you have only just started using the Unity Editor, you may not know how to use it. We will first explore the Unity Editor and then discuss the different features provided by Unity. We will then introduce the .NET profiles in Unity and the scripting backend offered by Unity. Finally, we will present how to use Visual Studio to develop Unity games.
We will cover the following key topics in this chapter:
Getting started with the Unity EditorWorking with different features in Unity.NET/C# and scripting in UnityBuilding Unity games with Visual StudioBefore starting, I highly recommend you first check whether your system can run the Unity Editor. The following table gives the minimum requirements to run the Unity Editor:
Whether you are an independent game developer or work in a team for a company, you need to do two things before installing or even downloading Unity:
Choose the right Unity release for you. Choose the right subscription plan for you.Therefore, before introducing how to install Unity and exploring the Unity Editor, let's first introduce the Unity release and subscription plans. We hope that by reading these contents, you can find the right release for you and choose a suitable subscription plan.
Nowadays, Unity offers two different release versions each year. They are as follows:
Tech Stream releasesLong-Term Support (LTS) releases:Figure 1.1 – Unity releases
You may not be quite sure which version of Unity is best to use in your project, so I will explain these two different releases so that you can get an idea of how to choose the right release for you.
LTS releases provide developers with maximum stability and full support for their projects, and they are the last Tech Stream releases of each year. With LTS releases, there are no new features or API changes. The updates of LTS releases address crashes, and fix bugs and any minor issues. As I mentioned at the beginning of this section, each year, Unity releases new versions of the LTS release, and each one is supported for 2 full years from the date of the announcement.
Therefore, if you are looking for performance and stability, or your project is already in production or in the middle of development, it is a good idea to use the latest LTS release version to ensure best performance and stability.
Note
At the time of writing (April 2022), there are two LTS releases, namely Unity 2020 LTS and Unity 2019.4. Unity 2020 LTS is the latest LTS release and has the same feature set as the Unity 2020.2 Tech Stream release. Alternatively, Unity 2019.4 is the legacy LTS release now.
The Tech Stream releases give developers who want to explore the latest in-progress features an option to use them to prepare for future projects. Unlike the LTS releases, a Tech Stream release will be released twice a year (typically published in the first and last quarters) and will only be supported until the next Tech Stream release is officially published.
Therefore, if you are preparing for your next project or working on prototyping and experimentation, you should try the Tech Stream releases.
Note
At the time of writing (April 2022), the latest Tech Stream release is Unity 2021.2.
By reading this section, I hope you have gained an understanding of the Unity releases, and you should be able to choose the right Unity release according to your situation.
When writing this book, I chose the latest LTS version, Unity 2020.3.
Unity is a widely used game engine, and many independent game developers use Unity to develop their games. But technically speaking, Unity is not a free game engine. In this section, I will introduce several different subscription plans offered by Unity. I hope that after reading this section, you can choose a subscription plan that suits your situation.
Unity offers a range of plans, from the free Personal plan for individual learners to Enterprise plans used by large organizations:
Figure 1.2 – The Plans and pricing page
Because each Unity plan has different eligibility requirements, you should choose the right plan for your project. Next, I will introduce the subscription plans:
The Personal plan is free and includes all the basic functionality of Unity. You can choose this plan if you work as an individual and have earned less than $100,000 in revenue or funding for your Unity project in the past 12 months. In addition, if you are a student or educator, you can get additional benefits, but before that, you need to join the GitHub Student Developer Pack to be verified.The Plus plan is a paid plan and offers more functionality and training resources, such as advanced cloud diagnostics and splash screen customization. If you have earned more than $100,000 but less than $200,000 in revenue from using Unity in the past 12 months, you should choose this plan.The Pro plan is also a paid plan. Compared with the Plus plan, you can get more technical support from Unity by using the Pro plan. If your organization has earned more than $200,000 in the last 12 months from any source, you must use the Pro plan or the Enterprise plan. The Enterprise plan is specifically for teams with at least 20 members and provides more support than the Pro plan. For example, a customer success manager from Unity will be assigned to your organization to provide guidance, orchestrate resources, and serve as an internal advocate.I hope this section was helpful for you in choosing the right Unity plan for your situation. Next, let's download and install the Unity Editor!
There are two different ways to download and install the Unity Editor. The first and recommended way to download and install Unity is to use the Unity Hub.
The Unity Hub is a management tool that can be used to manage all your Unity projects and Unity installations. We can take the following steps to install the Unity Hub and the Unity Editor:
To install the Unity Hub, visit the Download Unity page at https://unity3d.com/get-unity/download:Figure 1.3 – The Download Unity page
As you can see in the System requirements section in the preceding screenshot, the Unity Hub supports Windows, Mac OS X, Ubuntu, and CentOS.
Installing the Unity Hub is very easy; you just need to choose the folder where the Unity Hub is installed. Then, click on the Install button:Figure 1.4 – Unity Hub Setup
After installing the Unity Hub, select the Run Unity Hub option and click on the Finish button to launch the Unity Hub:Figure 1.5 – Completing Unity Hub Setup
I am using the latest version of Unity Hub (version 3.0.0) at the time of writing. If you have used previous versions of Unity Hub, you will find that the launch page of the new version of Unity Hub is completely different.
You need a Unity account to access the Unity Editor and the Unity Hub. If you don't have a Unity account yet, then you need to create a new one:Figure 1.6 – Unity Hub
When you sign into the Unity Hub for the first time, you will be asked to add an active license, as you can see at the top of the following screenshot. Click on the Manage licenses button to open the Licenses setting panel:Figure 1.7 – Click the Manage licenses button
There are two buttons available for you to add a new license. You can click either the Add button at the top-right corner or the Add license button:Figure 1.8 – The Licenses setting panel
Then, you have different options to activate the license. We have discussed the different Unity subscription plans in the previous section:
Figure 1.9 – Add new license
After adding the new license, we can start exploring the Unity Hub. From the Projects view, you can find a list of Unity projects that are tracked by the Unity Hub. You can also create a brand-new project by clicking the New project button at the upper-right corner of the Projects view, or you can import an existing project by clicking the Open button:Figure 1.10 – The Projects view
To install the Unity Editor, open the Installs view, where you can manage the installation of multiple versions of the Unity Editor:Figure 1.11 – The Installs view
There is a list of the Unity Editors that are installed and managed by the Unity Hub. Similar to the Projects view, you can download and install a new Unity Editor, or you can import an existing Unity Editor that is not managed by the Unity Hub, such as the Unity Editor that we installed using the Unity installer.
Open the Install Unity Editor panel by clicking the Install Editor button on the Installs view. Then, you will see the latest version of each release:Figure 1.12 – Install Unity Editor
Note
Unity 2018 LTS has reached the end of its support cycle, so you should not install it.
We will use the latest version of the Unity 2020 LTS release, so we need to install Unity 2020.3.13f1 here:
Figure 1.13 – Install Unity 2020.3.13f1
Then, we need to select the modules that need to be installed. As you can see in the preceding screenshot, Microsoft Visual Studio Community 2019 will be installed by default, which will be our Integrated Development Environment (IDE) to develop games in Unity.
Note
If you want to change the installation location, you can change it in the Installs settings of the Preferences panel.
Once it has been downloaded and installed, we are ready to start exploring the Unity Editor!
Sometimes, you may need a specific version that is not available through the Unity Hub, such as some older Unity versions. At this point, you can also install the Unity Editor a second way, which is through the Unity installer. You can use the Unity installer to download the previous versions of Unity:
Figure 1.14 – The Unity download archive page
Now, follow these steps to install the Unity Editor through the Unity installer:
To download a previous version of Unity, you should access the Unity download archive page at https://unity3d.com/get-unity/download/archive. Click on the Next button and choose the components of Unity that you want to download and install. The Unity installer should resemble the following screenshot:Figure 1.15 – The Unity installer
The Unity Editor is selected by default; in order to build games for different platforms, you also need to select the corresponding build support components. For example, if you want to build an Android game running on Android devices, you need to download and install the Android Build Support component:Figure 1.16 – Choosing components
Click the Next button, and then you need to choose download and install locations:Figure 1.17 – Choose Download and Install locations
After specifying where to download and install these files, click the Next button to download Unity:Figure 1.18 – Downloading and Installing
After the download and installation are complete, the Unity Editor icon will appear on your desktop.
The first thing we need to do is use the Unity Hub to create a new Unity project. As I mentioned in the previous section, we will create a brand-new project by clicking the New Project button at the upper-right corner of the Projects view.
Figure 1.19 – Creating a new project
As shown in the preceding screenshot, we can choose different Unity Editor versions for this new project, and Unity provides us with some built-in project templates, such as the 2D, 3D, HDRP, and URP templates. You can also download and install more templates from Unity, such as the VR template and the AR template. In the PROJECT SETTINGS section, you can set the name of the project and the location of the project.
Here, we will choose the default 3D project template and name our project UnityBook. Then, click on the Create project button. After that, the Unity Editor you previously selected will launch and open a new project for you:
Figure 1.20 – The Unity Editor
As you can see in the preceding screenshot, the Unity Editor layout organizes the most important windows for you. Specifically, the default layout divides the editor interface into five key areas. From top to bottom, they are as follows:
ToolbarHierarchy windowScene view and Game viewInspector windowProject windowNext, I will introduce these UI areas in order.
The Toolbar is always at the top of the Unity Editor interface, and it consists of several groups of controls:
Figure 1.21 – The Toolbar
From left to right, the first tool in the Toolbar is the transform tools set. The transform tools are used in the Scene view and allow you to pan around the Scene and move, rotate, and scale individual GameObjects in the Scene:
Figure 1.22 – The transform tools set
The next tool is the Gizmo handle position toggles set, which is used to define the position of any transform tool Gizmo in the Scene view:
Figure 1.23 – The Gizmo handle position toggles set
Then, you can find the Play, Pause, and Step buttons in the center. You can use these buttons in the Game view:
Figure 1.24 – The Play, Pause, and Step buttons
On the right side, let's take a look at the Unity Plastic SCM button first, which allows you to access the Plastic SCM version control and source code management tool in the Unity Editor directly. You can click the cloud button to open the Unity Services window, where you are able to access a lot of cloud services provided by Unity, such as the Cloud Build service, the Analytics service, and the Ads service.
You can also access your Unity account from the Account drop-down menu. There are two other drop-down menus on the right, namely Layers and Layout; you can control which objects in the Scene view appear using the Layers drop-down menu and change or create a new layout of your Unity Editor using the Layout drop-down menu:
Figure 1.25 – The Unity Collaborate and Unity Services buttons and the Unity Account, Layers, and Layout dropdowns
The second area is the Hierarchy window. As you can see in the following screenshot, the Hierarchy window in the Unity Editor displays everything in a Scene; the things in the Scene, such as Main Camera, Directional Light, and the 3D cube, are called GameObjects.
We can also organize all the objects in the game world in the Hierarchy window:
Figure 1.26 – The Hierarchy window
It is very easy to create a new GameObject in a Scene. You only need to right-click on the Hierarchy window, and a menu will pop up where you can select the object you want to create:
Figure 1.27 – Creating a new GameObject
It is worth noting that Unity uses parent-child hierarchies to organize GameObjects, so you can create one object as a child of another. If you want to create a new GameObject as a child of another GameObject, then you only need to select the parent GameObject first and then right-click to create the child GameObject:
Figure 1.28 – The parent-child hierarchy
Another way to create a parent-child hierarchy is to directly drag an existing GameObject onto the parent GameObject in the Hierarchy window:
Figure 1.29 – The parent-child hierarchy
As you can see in the preceding screenshot, we dragged the GameObject named Cube onto the GameObject named Child to create a parent-child hierarchy.
Figure 1.30 – Hiding and showing GameObjects
Another feature of the Hierarchy window is that it allows you to hide and show GameObjects in the Scene view without changing their visibility in the Game view or the final application.
The center of the default Unity Editor layout is the Scene view and the Game view, which is the most important window in the Unity Editor. The Scene view is an interactive view of the game world you are creating:
Figure 1.31 – The Scene view
You can use the Scene view to manipulate GameObjects and view them from various angles. Also, there are some useful tools available in the Scene view, such as the Scene Gizmo tool at the upper-right corner of the Scene view:
Figure 1.32 – The Scene Gizmo tool
It shows the current orientation of the Scene view camera and allows you to quickly modify the angle of the view and projection mode.
If you want to modify the settings of the Scene view camera, you can click the Camera button next to the Gizmos button to open the Scene Camera settings window:
Figure 1.33 – The Scene Camera settings
Here, you can adjust some settings of the Scene view camera, such as Field of View and Camera Speed.
A visual grid is another useful tool that you can use in the Scene view to help you align GameObjects by moving them to the nearest grid location:
Figure 1.34 – Toggle the visibility of the grid
As you can see in the preceding screenshot, you can also move a GameObject to a grid projected along the X, Y, or Z axes.
The last useful tool in the Scene view that I want to introduce is draw mode used in the Scene:
Figure 1.35 – The draw mode in the Scene
This is useful if your project uses the built-in render pipeline of Unity because a different draw mode in the Scene can help you understand and debug the lighting in it.
In the default layout, the Game view also appears in the same area as the Scene view. You can click the Game button to switch to the Game view from the Scene view:
Figure 1.36 – Click the Game button to switch to the Game view
The Game view represents your final published game. The content of the Game view is rendered from the camera(s) in your game. In the Game view, you cannot modify the viewing angle and projection mode at will, as with the Scene view. You need to modify the settings of the camera object to achieve this function:
Figure 1.37 – The Game view
You can run your game directly inside the Game view by clicking the Play button on the Toolbar. It's important to note that in Play mode, any changes you make are temporary and will be reset when you exit it; therefore, it is not a good idea to make lots of changes in play mode.
I want to introduce three tools in the Game view, namely Aspect, Maximize On Play, and Stats.
The Aspect drop-down menu is very useful when you develop games for different screens with different aspect ratios. You can select different values to test how your game looks on these screens, and you even can add custom values by clicking the plus button at the bottom of the menu:
Figure 1.38 – The Free Aspect drop-down menu
The second feature is called Maximize On Play, which can maximize the Game view for a full-screen preview when you enter play mode:
Figure 1.39 – The Maximize On Play button
The third feature is called Stats. This feature is useful because it can display the rendering statistics about your game's audio and graphics. Therefore, you can use it for monitoring the performance of your game while in play mode:
Figure 1.40 – The Stats window
In the Scene view, you can view and adjust the game world you are creating. In the Game view, you can see your final game. So, this area is very important in the Editor. Next, let's take a look at the UI area related to a specific GameObject in the Scene.
If you want to modify the properties of a GameObject or a component on a GameObject, you need to use the Inspector window.
You can select a GameObject in the Scene view or the Hierarchy window, and then you will see the properties and the components of it in the Inspector window:
Figure 1.41 – The Inspector window of a GameObject
You can modify these properties directly in the Inspector window, which also provides some useful tools that can help you modify your GameObjects.
For example, if you want to copy the values of a component on a GameObject, you can right-click on the component, and then a menu will pop up; from there, you can select the Copy Component command:
Figure 1.42 – Copy Component
Not only can the GameObjects in the Scene view be inspected but also the digital assets in the Project window. You can select a digital asset in the Project window, and the Inspector window will display the settings that control how Unity imports and uses the asset at runtime:
Figure 1.43 – The Inspector window of an asset
In this section, we learned how to view and modify the properties of a GameObject and asset through the Inspector window.
The final window I will introduce is the Project window. In the Project window, you can find all the digital assets of your project. The Project window works like a file browser, organizing assets files in folders:
Figure 1.44 – The Project window
The Project window is the main way to navigate and find assets in your game. It provides two ways to search assets, by type or label:
Figure 1.45 – Searching assets by type
It is very easy to import external digital assets or create an asset inside the Unity Editor directly. You just need to right-click on the Project window and a menu will pop up where you can create a new asset or import an existing asset:
Figure 1.46 – Creating an asset
I hope you now have a good understanding of the Unity Editor by reading this section. Next, I will introduce what a game engine is and what important features Unity provides as a game engine.
Tausende von E-Books und Hörbücher
Ihre Zahl wächst ständig und Sie haben eine Fixpreisgarantie.
Sie haben über uns geschrieben: