Learn Unity For 2D Game Development

Book description

2D games are everywhere, from mobile devices and websites to game consoles and PCs. Timeless and popular, 2D games represent a substantial segment of the games market.

In Learn Unity for 2D Game Development, targeted at both game development newcomers and established developers, experienced game developer Alan Thorn shows you how to use the powerful Unity engine to create fun and imaginative 2D games.

Written in clear and accessible language, Learn Unity for 2D Game Development will show you how to set up a step-by-step 2D workflow in Unity, how to build and import textures, how to configure and work with cameras, how to establish pixel-perfect ratios, and all of this so you can put that infrastructure to work in a real, playable game. Then the final chapters show you how to put what you've already made to work in creating a card-matching game, plus you'll learn how to optimize your game for mobile devices.

Table of contents

  1. Cover
  2. Title
  3. Copyright
  4. Contents at a Glance
  5. Contents
  6. About the Author
  7. About the Technical Reviewer
  8. Acknowledgments
  9. Introduction
  10. Chapter 1: Unity Basics for 2D Games
    1. Unity Projects, Assets, and Scenes
      1. Project Wizard and Project Panel
      2. Assets and Project Files
      3. Scenes
    2. Navigating Scenes and Viewports
    3. GameObjects, Transforms, and Components
    4. Cameras
    5. Meshes and Geometry
    6. Scripting and the Unity API
      1. MonoDevelop
      2. Components
    7. Performance, Profiling, and the Stats Panel
      1. The Profiler
      2. The Stats Panel
    8. Editor Add-Ons
    9. Unity Interface Configuration
    10. Summary
  11. Chapter 2: Materials and Textures
    1. Using Materials and Textures
      1. Getting Started with Materials
      2. Mesh Renderers
      3. Shaders
      4. Working with Textures
    2. Materials for 2D Games
      1. Method 1: Use White Ambient Light
      2. Method 2: Use Light-Immune Shaders
    3. Creating Textures
      1. Rule #1: Power-2 Dimensions
      2. Rule #2: Retain Quality
      3. Rule #3: Expand Alpha Channels for Transparency
      4. Creating Alpha Textures in Adobe Photoshop
      5. Creating Alpha Textures in GIMP
    4. Importing Textures into Unity
      1. Importing an Alpha Texture into Unity
    5. Summary
  12. Chapter 3: Quick 2D Workflow
    1. Getting Started at Making “2D Alien Invasion”
    2. Adding the Player and Enemies to the Scene
    3. Implementing Player Movement
    4. Implementing Player Weapons with Prefabs
      1. Creating an Ammo Prefab Object
      2. Implementing the Ammo Trajectory
      3. Creating the Prefab Ammo Object
      4. Defining the Cannon Point
      5. Coding the Firing of Ammo
    5. Implementing Moving Enemies and Collision
      1. The EnemyController.cs Script
      2. Setting the BoxCollider as a Trigger Volume
      3. Adding a RigidBody Component
    6. Adding a Level Background
    7. Moving Forward and Project Limitations
    8. Summary
  13. Chapter 4: Customizing the Editor with Editor Classes
    1. Editor Classes
    2. Getting Started with Batch Rename
      1. BatchRename.cs
      2. Creating a Folder for Editor Extensions
    3. Adding Batch Rename to the Application Menu
      1. The CreateWizard Function
      2. Testing the Batch Rename Menu Option
    4. Reading Object Selections in the Scene
      1. Making Use of Selection in BatchRename.cs
      2. Testing Object Selections in Scene
    5. Adding User Input to the Batch Rename Window
    6. Completing the Batch Rename Feature
    7. Summary
  14. Chapter 5: Procedural Geometry and Textured Quads
    1. Getting Started with the CreateQuad Feature
    2. Setting the Quad’s Anchor Point
    3. Specifying the Asset Path
    4. Generating the Quad Mesh
      1. Step 1—Create Vertices
      2. Step 2—Create Quad as an Asset
      3. Step 3—Instantiate Quad in Scene
    5. Testing the Quad Mesh Generator
    6. Summary
  15. Chapter 6: Generating Atlas Textures
    1. Getting Started with Atlas Textures
    2. Configuring Texture Inputs
    3. Atlas Textures and UVs
    4. Generating an Atlas – Step 1: Optimizing Texture Inputs
    5. Generating an Atlas – Step 2: Atlas Generation
    6. Generating an Atlas – Step 3: Saving the Atlas Prefab
    7. Testing the Atlas Texture
    8. Summary
  16. Chapter 7: UVs and Animation
    1. Creating a Dockable Editor
      1. Starting an Editor GUI — Selecting an Atlas
      2. UV Editor—Adding an Input for the Atlas Prefab
      3. Continuing with the GUI—Selecting a Texture
      4. UVs and Manual Mode
      5. Editing Mesh UVs
      6. Putting It All Together—Finishing the UV Editor
    2. Flipbook Animation
    3. Summary
  17. Chapter 8: Cameras and Pixel Perfection
    1. Perspective versus Orthographic Cameras
    2. World Units and Pixels
      1. Position Objects
      2. Field of View
      3. Camera Size
      4. Pixel Positioning
    3. Pixel Perfection
    4. Other Useful Camera Tricks
      1. Depth
      2. Advanced Depth
    5. Summary
  18. Chapter 9: Input for 2D Games
    1. Detecting Mouse Clicks on Objects Automatically
    2. Detecting Mouse Clicks on Objects Manually
    3. Coding a Mouse Cursor
    4. Working with Keyboard Input
    5. Virtual Axes and Buttons—Input Abstraction
    6. Mobile Input—Android, iOS, and Windows Phone
      1. Detecting Touch Events on Mobiles
      2. Mapping Touches to Mouse Input
      3. Conditional Code Compilation
    7. Summary
  19. Chapter 10: Getting Started with a 2D Game
    1. Game Design—Card Matching
    2. Getting Started with the Game
      1. Importing Assets
      2. Generating an Atlas Texture
      3. Generating Card and Cursor Quads
      4. Assigning Materials and UVs
      5. Camera and Resolution
    3. Configuring the Scene—Setting Up the Cards
      1. Setting Card Properties
      2. Positioning and Arranging the Cards
      3. Positioning and Arranging the Cards—Starting
      4. Positioning and Arranging the Cards—Completing
    4. The Game Manager
      1. Shuffling the Cards
      2. Handling User Input
      3. Turn Management
    5. Summary
  20. Chapter 11: Completing the 2D Card Game
    1. Networking in Unity — Getting Started
    2. Establishing a Server
    3. Establishing a Client
    4. Testing Networked Functionality
    5. Network Views
    6. Making an Authoritative Server
      1. Using RPCs
    7. RPCs from Client to Server
    8. Summary
  21. Chapter 12: Optimization
    1. Optimization—What Is It?
    2. Tip #1—Minimize Vertex Count
    3. Tip #2—Minimize Materials
    4. Tip #3—Minimize UV Seams
    5. Tip #4—Recycle Texture Space by Overlapping UVs
    6. Tip #5—Use Per-Platform Texture Settings
    7. Tip #6—Cache Components and Objects
    8. Tip #7—Avoid Using Update
    9. Tip #8—Minimize Colliders
    10. Tip #9—Avoid OnGUI and the GUI class
    11. Tip #10—Use Object Pooling
    12. Tip #11—Use Static Batching
    13. Tip #12—Utilize Skyboxes
    14. Tip #13—Avoid Dynamic Lights and Shadows
    15. Tip #14—Bake It; Don’t Simulate It
    16. Summary
  22. Chapter 13: Wrapping Things Up
    1. GUIs and Resolution
    2. Tiles and Tile-sets
    3. Atlas Textures
    4. Fonts
    5. Unity Alternatives
      1. Engines
      2. Libraries and APIs
    6. Asset Creation
      1. Image Editing Software
      2. Vector Graphic Software
      3. 2D Animation Software
    7. Summary
  23. Index

Product information

  • Title: Learn Unity For 2D Game Development
  • Author(s): Alan Thorn
  • Release date: October 2013
  • Publisher(s): Apress
  • ISBN: 9781430262305