Book Image

Game Development with Unity for .NET Developers

By : Jiadong Chen
Book Image

Game Development with Unity for .NET Developers

By: Jiadong Chen

Overview of this book

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.
Table of Contents (16 chapters)
1
Part 1: Basic Unity Concepts
4
Part 2: Using C# Scripts to Work with Unity's Built-In Modules
9
Part 3: Advanced Scripting in Unity

Working with different features in Unity

Nowadays, Unity is no longer just a game engine but also a creative tool widely used in various industries. However, Unity still retains its game engine roots, and it remains one of the most popular game engines. To learn how to use Unity to develop games, you must first understand what features Unity provides for game developers as a game engine.

In fact, almost all game engines provide similar functional modules to Unity to game developers. So, the first question is, what exactly is a game engine?

What is a game engine?

The term game engine is widely used in the game industry, but not everyone knows what this term means, especially new game developers. So, I will explain what a game engine is and, at the same time, introduce the corresponding functions in Unity.

A game engine is not just a computer graphics renderer. Of course, rendering is an important function of a game engine, but the process of creating a game is much more complicated than just rendering.

As a game developer, you need to import different types of digital assets, such as 3D models, 2D textures, and audio, and most of these digital assets are not created inside a game engine. Therefore, a game engine should provide the function of managing digital assets. In addition to digital assets, you also need to use scripts to add game logic to guide these assets to perform correct behaviors, such as character interactions.

UI is another integral part of a game, and even some gameplay is based on UI. Therefore, a good game engine should provide an easy-to-use and powerful UI toolkit to develop user interfaces for games.

You can use other software to develop animation files and import them into a game engine, but in order for animation files to be played and controlled correctly in the game, the game engine needs to provide an animation feature.

At the same time, a physical effect is a common function in modern games, so a powerful game engine should provide a physical function so that game developers do not need to implement a physical effect from scratch.

There is no doubt that adding video and audio to your game can make your game livelier and more interesting. With audio especially, suitable background music and some appropriate sound effects can make your game feel completely different. Even if it is just a prototype, background music and sound effects can make the game more complete and more professional. Therefore, although many people often ignore the functions of video and sound when talking about game engines, I don't think that a game engine without video and audio functions is a good one.

As you can see, there are many features in a game engine for game developers to develop their games. A game engine integrates all aspects of creating a game to create a complete game user experience. So, in game development, you will deal with different functions. For example, you may need to properly manage digital assets and create appropriate digital assets for your game engine to optimize performance at runtime, or you may need to know how to use the scripting function provided by the game engine you are using to develop logic for your game.

As one of the most popular game engines, Unity also provides the aforementioned functions. In the following subsection, I will introduce these functions in Unity.

Features in Unity

Like other excellent game engines, Unity also provides many functions for game developers. You will be introduced to these functions in the following sections.

Graphics

The first feature I want to introduce is graphics in Unity. You can use Unity's graphics features to create beautiful, optimized graphics on various platforms:

Figure 1.47 – A Unity HDRP template Scene

A render pipeline performs a series of operations that render the contents of a Scene on a screen. There are three render pipelines available in Unity:

  • The Built-in Render Pipeline, which is the default render pipeline in Unity. You cannot modify this render pipeline.
  • The Universal Render Pipeline (URP), which allows developers to customize and create optimized graphics for different platforms.
  • The High Definition Render Pipeline (HDRP), which focuses on cutting-edge, high-fidelity graphics on high-end platforms.

In addition, you can also create your own render pipeline by using the Scriptable Render Pipeline API in Unity. We will introduce it in detail in Chapter 8, The Scriptable Render Pipeline in Unity.

Scripting

Scripting is another essential feature of Unity. You need scripts to implement the game logic in your games.

The Unity engine is built with native C/C++ internally, but it offers scripting APIs in C#, so you do not have to learn C/C++ to create a game. In the following sections and chapters, you will learn more about the concepts of scripting.

UI

UI is very important for a game, and Unity offers three different UI solutions for game developers:

  • The Immediate Mode Graphical User Interface (IMGUI)
  • The Unity UI (uGUI) package
  • The UI Toolkit

The IMGUI is a relatively old UI solution in Unity, and it is not recommended for building a runtime UI. The UI Toolkit is the latest UI solution; however, it is still missing some features that you can find in the uGUI package and the IMGUI. The uGUI package is a mature UI solution in Unity, which is widely used in the game industry. We will introduce the uGUI package in detail in Chapter 3, Developing UI with the Unity UI System.

Animation

Animation can make your game more vivid. Unity provides a powerful animation feature called Mecanim that allows you to retarget an animation, control the weight of it at runtime, and call events from the animation playback.

We will introduce Unity's animation system in Chapter 4, Creating Animations with the Unity Animation System.

Physics

Physical simulation is an indispensable feature in certain types of games, and some gameplays are even based entirely on physical simulation. There are different physics engine implementations in Unity, and you can select one according to your game needs.

We will introduce Unity's physics engine implementations in Chapter 5, Working with the Unity Physics System.

Video and audio

Good background music, sound effects, and video can make your game stand out. This is a feature that cannot be ignored. Unity provides video and audio features, allowing your game to play videos on different platforms, and supports real-time mixing and full 3D spatial sound effects.

We will discuss video and audio more in Chapter 6, Integrating Audio and Video in a Unity Project.

Assets

You can import your digital asset files into the Unity Editor, such as 3D models and 2D textures. Unity offers an Asset Import Pipeline to process these imported assets. You can also customize the import settings to control how Unity imports and uses the assets at runtime.

We will introduce assets management and serialization in Chapter 10, Serialization System and Assets Management In Unity and Azure.

We've briefly introduced the functions that a game engine needs to provide and the functions provided by Unity. Next, let's introduce .NET/C# and scripting in Unity.