Home Page Icon
Home Page
Table of Contents for
Unity 5: Learning C# by Developing Games
Close
Unity 5: Learning C# by Developing Games
by Chris Dickinson, John P. Doran, Greg Lukosek
Unity 5: Learning C# by Developing Games
Unity 5: Learning C# by Developing Games
Table of Contents
Unity 5: Learning C# by Developing Games
Unity 5: Learning C# by Developing Games
Credits
Preface
What this course covers
What you need for this course
Who this course is for
Reader feedback
Customer support
Downloading the example code
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
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Table of Contents
Next
Next Chapter
Unity 5: Learning C# by Developing Games
Unity 5: Learning C# by Developing Games
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset