万本电子书0元读

万本电子书0元读

顶部广告

Unity 5: Learning C# by Developing Games电子书

售       价:¥

37人正在读 | 0人评论 9.8

作       者:Greg Lukosek,John P. Doran,Chris Dickinson

出  版  社:Packt Publishing

出版时间:2016-08-01

字       数:870.2万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:此类商品不支持退换货,不支持下载打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Explore every nook and cranny of Unity 5 to turn your imaginations into reality About This Book Demystify the C# programming language in Unity 5.x. Unleash the power of Unity to create a wide variety of projects in numerous genres and formats. Master the art of optimization for Unity 5.x applications with tips and techniques that will further enhance your game. Who This Book Is For Beginner level Unity developers who do not have much programming experience. What You Will Learn Master the art of applying C# in Unity. Get to know about techniques to turn your game idea into working project. Use loops and collections efficiently in Unity to reduce the amount of code. Create and code a good-looking functional UI system for your game. Find out how to create exciting and interactive games using GUIs. Work with different animation assets and components to enhance your game further. Personalize your game by learning how to use Unity’s advanced animation system. Create, visualize, and edit animated creatures to add to your already amazing game. Familiarize yourself with the tools and practices of game development Discover how to create the Game Manager class to, generate game levels, and develop UI for the game. Use the Unity Profiler to find bottlenecks anywhere in your application, and discover how to resolve them. Implement best practices for C# *ing to avoid common mistakes In Detail Unity is a cross-platform game engine that is used to develop 2D and 3D video games. Unity 5 is the latest version, and adds a real-time global illumination to the games; and its powerful new features help to improve a game’s efficiency. If you love games and want to learn how to make them but have no idea where to begin, then this course is built just for you. This learning path is divided into three modules which will take you in this incredible journey of creating games. The course begins with getting you started with programming behaviors in C# so that you can create 2D games in Unity. You will begin by installing Unity and learning about its features. You will learn how to perform object-oriented programming and discover how to manage the game play loop, generate game levels, and develop a simple UI for the game. By the time this module comes to a close, you will have mastered the art of applying C# in Unity. It is now time we put into use what we learned in the previous module into reality as we move onto the second module. Here, we will be building 7-8 action-packed games of different difficulty levels. Each project will focus on key Unity features as well as game strategy development. This module will mark your transformation from an application developer to a full-fledged Unity game developer. Who wouldn’t love a game that is fully perfect, functional, and without any glitchesThe third module deals with just that by teaching how to enhance your game by learning game optimization skills. Here, you’ll gain an understanding of possible solutions to any problem and how to implement them. You will then learn everything you need to know about where performance bottlenecks can be found, why they happen, and how to work around them. With this massive wealth of knowledge, at the end of this learning path, you will be able to leverage an array of game development techniques to create your own basic games while resolving any issues that you encounter. Style and approach This learning path should be treated as the complete package necessary for building games. It is a step-by-step guide to develop a game from scratch by applying the fundamentals of C# and Unity *ing, with a reference guide in the end to solve all your gaming problems.
目录展开

Unity 5: Learning C# by Developing Games

Table of Contents

Unity 5: Learning C# by Developing Games

Credits

Preface

What this course covers

What you need for this course

Who this course is for

Conventions

Reader feedback

Customer support

Downloading the example code

Downloading the color images of this book

Errata

Piracy

Questions

1. Module 1

1. Discovering Your Hidden Scripting Skills and Getting Your Environment Ready

Prerequisite knowledge to use this book

Dealing with scriptphobia

Downloading Unity

Obtaining a free license

Teaching behavior to GameObjects

Using Unity's documentation

Do I need to know all that?

C# documentation – where to find it? Do I need it at all?

The Unity community – asking others for help

Working with C# script files

Lots of files can create a mess

Why does my Project tab look different?

Creating a C# script file

Introducing the MonoDevelop code editor

Syncing C# files between MonoDevelop and Unity

Opening LearningScript in MonoDevelop

The namespace – highlighted in blue

The class definition – highlighted in green

Watching for possible gotchas while creating script files in Unity

Fixing synchronization if it isn't working properly

Adding our script to GameObject

Instance? What is it?

Summary

2. Introducing the Building Blocks for Unity Scripts

Understanding what a variable is and what it does

Naming a variable

A variable name is just a substitute for a value

Creating a variable and seeing how it works

Declaration

Assignment

Click on Play!

Changing variables

Watching for a possible gotcha when using public variables

What is a method?

Using the term "method" instead of "function"

Method names are substitutes, too

Introducing the class

Inheritance

The Start(), Update(), and Awake() methods and the execution order

Components that communicate using dot syntax

What's with the dots?

Making decisions in code

Using the NOT operator to change the condition

Checking many conditions in an if statement

Using else if to make complex decisions

Making decisions based on user input

Paper and pencil are powerful tools

Summary

3. Getting into the Details of Variables

Writing C# statements properly

Understanding component properties in Unity's Inspector

Variables become component properties

Unity changes script and variable names slightly

Changing a property's value in the Inspector panel

Displaying public variables in the Inspector panel

Private variables

Naming your variables properly

Beginning variable names with lowercase

Using multiword variable names

Declaring a variable and its type

The most common built-in variable types

Assigning values while declaring a variable

Where you declare a variable is important

Variable scope – determining where a variable can be used

Summary

4. Getting into the Details of Methods

Using methods in a script

Naming methods properly

Beginning method names with an uppercase letter

Using multiword names for a method

Parentheses are part of the method's name

Defining a method the right way

The minimum requirements for defining a method

Understanding parentheses – why are they there?

Specifying a method's parameters

How many parameters can a method have?

Returning a value from a method

Returning the value

Example

Summary

5. Lists, Arrays, and Dictionaries

What is an array?

Declaring an array

Storing items in the List

Common operations with Lists

List<T> versus arrays

Retrieving the data from the Array or List<T>

Checking the size

ArrayList

Dictionaries

Accessing values

How do I know what's inside my Hashtable?

Summary

6. Loops

Introduction to loops

The foreach loop

The for loop

An example

The while loop

while versus for loops

Loops in statements

Modulo

Searching for data inside an array

Breaking the loop

Summary

7. Object, a Container with Variables and Methods

Working with objects is a class act

Few facts

Example

Instantiating an object

Bored yet?

Using methods with objects

Custom constructors

Overloading

Summary

8. Let's Make a Game! – From Idea to Development

Your first game – avoiding the trap of the never-ending concept

The idea

Game mechanics and core components

Breaking a complex idea into smaller parts

Jake on the mysterious planet – the feature list

Procedural level generation

An animated 2D character

Physics

Mouse and touch controls

Collectables and obstacles

Scoring

UI – the user interface

Target platform and resolution

Target screen resolution

Summary

9. Starting Your First Game

Setting up a new Unity project for our game

Backup

Keeping your project clean

Preparing the player prefab

Rigidbody2D

CircleCollider2D

PlayerController

User input

Jump

Animator

Running

Code

PlayerController.cs

Summary

10. Writing GameManager

Gameplay loops

Singleton class

Starting the game

Setting up input keys

Using triggers

Restarting the game

Setting up the player starting position

Code in this chapter

Summary

11. The Game Level

Generating levels versus designed levels

Creating a level chunk

Planning the LevelGenerator class

Writing LevelGenerator

Commenting on your code

Creating a copy of the level piece

Instantiating

Vector3

Testing LevelGenerator

Extending the level

The code used in this chapter

Summary

12. The User Interface

Introducting the Unity UI

Views

Constructing the view UI – how to keep things clean

Target screen resolution

Recognizing events

Buttons

A simple button

Image

The Button component

Interaction

The Button action

Hiding and showing the Canvas

Reference exceptions

GameView

Game Over

The code in this chapter

Summary

13. Collectables — What Next?

Collectables

The coin prefab

The Collectable class

High score and persisting data

The Update function and UI values

What next?

The code in this chapter

Summary

2. Module 2

01. 2D Twin-stick Shooter

Project overview

Your objectives

Prerequisites

Setting up the project

Creating our scene

Scripting 101

Implementing player movement

Shooting behavior

Creating enemies

Adding GameController to spawn enemy waves

Particle systems for enemy explosion

Adding in sound effects/music

Adding in points, score, and wave numbers

Publishing the game

Summary

Challenges

2. Creating GUIs

Project overview

Your objectives

Prerequisites

Creating the main menu level

Adding a header text object

Adding main menu buttons

Pausing the game

Restarting the game

Creating an Options menu

Summary

Challenges

3. GUIs Part 2 – Clicker Game

Project overview

Your objectives

Prerequisites

Starting our project

Recording and displaying clicks

Working with accessors (get/set functions)

Tooltip and Header attributes

Explaining GameController's functionality

Creating a shop

Making the list scrollable with ScrollView

Opening/closing the shop

Purchasing upgrades

Working with enumerations

Switch statements

Explaining the StoreItem class

Filling in Item descriptions

Summary

Challenges

4. Mobile Endless Game – Procedural Content

Project overview

Your objectives

Prerequisites

Project setup

Adding the background

Adding a simple animated character

Making a repeating background

Repeating background script

Working with sorting layers

Creating our player behaviour

Stopping the game

Creating obstacles

Spawning obstacles at runtime

Game start and end behaviours

Keeping score

Summary

Challenges

5. Shooting Gallery – Working with Animations and Tweens

Project overview

Your objectives

Prerequisites

Project setup

Creating the environment

Adding a target

Animating the duck using Unity's animation system

Playing Unity animations via code

Animation using iTween

Creating moving targets

Creating many targets

Creating waves of targets

Adding in a time limit

Adding in Score/High score

PlayerPrefs

Set

Get

Summary

Project completed

Challenges

6. Side-scrolling Platformer

Project overview

Your objectives

Prerequisites

Project setup

Tile-based level creation

Working with arrays

Creating our player

Adding Jump functionality

Working with Gizmos

Smoothing out player movement

Restricting Jumping

Preventing the player getting stuck

Creating Collectibles

Adding new objects to our level builder

Switch statements continued

Keeping score

Singletons

Winning the game

Summary

Challenges

7. First Person Shooter Part 1 – Creating Exterior Environments

Project overview

Your objectives

Prerequisites

Project setup

Level design 101 – planning

Introduction to terrain

Height maps

Hand sculpting

Exterior environment – terrain

Adding color to our terrain – textures

Adding multiple textures to a terrain

Adding water

Adding trees

Adding in details – grass

Building atmosphere

Summary

Challenges

8. First-person Shooter Part 2 – Creating Interior Environments

Project overview

Your objectives

Prerequisites

Project setup

Creating architecture overview

3D modelling software

Constructing geometry with brushes

Modular tilesets

Mix and match

Importing assets

Creating tiles

Placing tiles with grid snapping

Creating and placing props

Lightmapping quickstart

Summary

Challenges

9. First Person Shooter Part 3 – Implementing Gameplay and AI

Project overview

Your objectives

Setting up the project

Creating our player

Adding a flashlight

Creating our weapon

Creating our camera

Shooting our camera

Creating an enemy

State machines 101

Enemy movement

Advanced FSMs

Damaging and killing enemies

Using controller input

Moving to other levels

Summary

Challenges

10. Building an In-Game Level Editor

Project overview

Your objectives

Prerequisites

Level editor – introduction

Lists

Level editor – adding/removing walls at runtime

Level editor – toggling editor, GUI, and selecting additional tiles

The anatomy of a IMGUI control

ControlType

Content

GUI.Button

GUILayout

Level editor – saving/loading levels to file

FileStreams

BinaryFormatter

Summary

Challenges

11. Finishing Touches

Project overview

Your objectives

Prerequisites

Setting up the build settings

Customizing your exported project via the player settings

Building an installer for Windows

Summary

Challenges

3. Module 3

1. Detecting Performance Issues

The Unity Profiler

Launching the Profiler

Editor or standalone instances

Editor profiling

The Unity Webplayer connection

Remote connection to an iOS device

Remote connection to an Android device

The Profiler window

Controls

CPU Area

The GPU Area

The Rendering Area

The Memory Area

The Audio Area

The Physics 3D/2D Area

Best approaches to performance analysis

Verifying script presence

Verifying script count

Minimizing ongoing code changes

Minimizing internal distractions

Minimizing external distractions

Targeted profiling of code segments

Profiler script control

Custom CPU Profiling

Saving and loading Profiler data

Saving Profiler data

Loading Profiler data

Final thoughts on Profiling and Analysis

Understanding the Profiler

Reducing noise

Focusing on the issue

Summary

2. Scripting Strategies

Cache Component references

Obtaining Components using the fastest method

Removing empty callback declarations

Avoiding the Find() and SendMessage() methods at runtime

Static classes

Singleton Components

Assigning references to pre-existing objects

A global messaging system

A globally accessible object

Registration

Message processing

Implementing the messaging system

Message queuing and processing

Implementing a custom message

Message registration

Message sending

Message cleanup

Wrapping up the messaging system

Disabling unused scripts and objects

Disabling objects by visibility

Disabling objects by distance

Consider using distance-squared over distance

Avoid retrieving string properties from GameObjects

Update, Coroutines, and InvokeRepeating

Consider caching Transform changes

Faster GameObject null reference checks

Summary

3. The Benefits of Batching

Draw Calls

Materials and Shaders

Dynamic Batching

Vertex attributes

Uniform scaling

Dynamic Batching summary

Static Batching

The Static flag

Memory requirements

Material references

Static Batching caveats

Edit Mode debugging of Static Batching

Avoiding instantiating static meshes at runtime

Visibility and rendering

Static Batching summary

Summary

4. Kickstart Your Art

Audio

Loading audio files

Profiling audio

Additional loading options

Encoding formats and quality levels

Audio performance enhancements

Minimize active Audio Source count

Minimize Audio Clip references

Enable Force to Mono for 3D sounds

Resample to lower frequencies

Consider all encoding formats

Beware of streaming

Apply Filter effects through Mixer groups to reduce duplication

Use "WWW.audioClip" responsibly

Consider Audio Module files for background music

Texture files

Compression formats

Texture performance enhancements

Reduce Texture file size

Use Mip Maps wisely

Manage resolution downscaling externally

Adjust Anisotropic Filtering levels

Consider Atlasing

Adjust compression rates for non-square Textures

Sparse Textures

Procedural Materials

Mesh and animation files

Reducing polygon count

Tweaking Mesh Compression

Use Read-Write Enabled appropriately

Import/calculate only what's needed

Consider baked animations

Let Unity optimize meshes

Combine meshes

Summary

5. Faster Physics

Physics Engine internals

Physics and time

The Fixed Update loop

Maximum Allowed Timestep

Physics updates and runtime changes

Static and Dynamic Colliders

Collision detection

Collider types

The Collision Matrix

Rigidbody active and sleeping states

Ray and object casting

Physics performance optimizations

Scene setup

Scaling

Positioning

Mass

Use Static Colliders appropriately

Optimize the Collision Matrix

Prefer discrete collision detection

Modify the FixedUpdate frequency

Adjust the Maximum Allowed Timestep

Minimize cast and bounding-volume checks

Avoid complex Mesh Colliders

Use simpler primitives

Use simpler Mesh Colliders

Avoid complex physics components

Let physics objects sleep

Modify Solver Iteration Count

Optimizing ragdolls

Reduce Joints and Colliders

Avoid inter-ragdoll collisions

Disable or remove inactive ragdolls

Know when to use physics

Consider upgrading to Unity 5

Summary

6. Dynamic Graphics

Profiling rendering issues

GPU profiling

The Frame Debugger

Brute force testing

CPU-bound

Multithreaded rendering

GPU Skinning

Front end bottlenecks

Level Of Detail

Disable GPU Skinning

Reduce tessellation

Back end bottlenecks

Fill rate

Overdraw

Occlusion Culling

Shader optimization

Consider using Shaders intended for mobile platforms

Use small data types

Avoid changing precision while swizzling

Use GPU-optimized helper functions

Disable unnecessary features

Remove unnecessary input data

Only expose necessary variables

Reduce mathematical complexity

Reduce texture lookups

Avoid conditional statements

Reduce data dependencies

Surface Shaders

Use Shader-based LOD

Memory bandwidth

Use less texture data

Test different GPU Texture Compression formats

Minimize texture sampling

Organize assets to reduce texture swaps

VRAM limits

Texture preloading

Texture thrashing

Lighting and Shadowing

Forward Rendering

Deferred Shading

Vertex Lit Shading (legacy)

Real-time Shadows

Lighting optimization

Use the appropriate Shading Mode

Use Culling Masks

Use Baked Lightmaps

Optimize Shadows

Optimizing graphics for mobile

Minimize Draw Calls

Minimize the Material count

Minimize texture size and Material count

Make textures square and power of 2

Use the lowest possible precision formats in Shaders

Avoid Alpha Testing

Summary

7. Masterful Memory Management

The Mono platform

The compilation process

Manual JIT compilation

Memory usage optimization

Unity memory domains

Native memory

Managed memory

Garbage collection

Memory fragmentation

Garbage collection at runtime

Threaded garbage collection

Garbage collection tactics

Value types and Reference types

Pass by value and pass by reference

Structs are Value types

Arrays are Reference types

Strings are immutable Reference types

String concatenation

Boxing

The importance of data layout

The Unity API

The foreach loops

Coroutines

Closures

.NET library functions

Temporary work buffers

Object pooling

Prefab pooling

Poolable Components

The Prefab pooling system

Prefab pools

Object spawning

Instance prespawning

Object despawning

Prefab pool testing

Prefab pooling and Scene loading

Prefab pooling summary

The future of Mono and Unity

Summary

8. Tactical Tips and Tricks

Editor hotkey tips

GameObjects

Scene View

Arrays

Interface

Other

Editor interface tips

General

The Inspector View

The Project View

The Hierarchy View

The Scene and Game Views

Play Mode

Scripting tips

General

Attributes

Variable attributes

Class attributes

Logging

Useful links

Custom editors/menus tips

External tips

Other tips

Summary

A. Bibliography

Index

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部