Unity Multiplayer Games

Book description

Take your gaming development skills into the online multiplayer arena by harnessing the power of Unity 4 or 3. This is not a dry tutorial – it uses exciting examples and an enthusiastic approach to bring it all to life.

  • Create a variety of multiplayer games and apps in the Unity 4 game engine, still maintaining compatibility with Unity 3.
  • Employ the most popular networking middleware options for Unity games
  • Packed with ideas, inspiration, and advice for your own game design and development

In Detail

Unity is a game development engine that is fully integrated with a complete set of intuitive tools and rapid workflows used to create interactive 3D content. Multiplayer games have long been a staple of video games, and online multiplayer games have seen an explosion in popularity in recent years. Unity provides a unique platform for independent developers to create the most in-demand multiplayer experiences, from relaxing social MMOs to adrenaline-pumping competitive shooters.

A practical guide to writing a variety of online multiplayer games with the Unity game engine, using a multitude of networking middleware from player-hosted games to standalone dedicated servers to cloud multiplayer technology. You can create a wide variety of online games with the Unity 4 as well as Unity 3 Engine.

You will learn all the skills needed to make any multiplayer game you can think of using this practical guide. We break down complex multiplayer games into basic components, for different kinds of games, whether they be large multi-user environments or small 8-player action games. You will get started by learning networking technologies for a variety of situations with a Pong game, and also host a game server and learn to connect to it.Then, we will show you how to structure your game logic to work in a multiplayer environment. We will cover how to implement client-side game logic for player-hosted games and server-side game logic for MMO-style games, as well as how to deal with network latency, unreliability, and security.

You will then gain an understanding of the Photon Server while creating a star collector game; and later, the Player.IO by creating a multiplayer RTS prototype game. You will also learn using PubNub with Unity by creating a chatbox application. Unity Multiplayer Games will help you learn how to use the most popular networking middleware available for Unity, from peer-oriented setups to dedicated server technology.

Table of contents

  1. Unity Multiplayer Games
    1. Table of Contents
    2. Unity Multiplayer Games
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    7. Preface
      1. Unity IDE crash course
      2. What this book covers
      3. What you need for this book
      4. Who this book is for
      5. Conventions
      6. Reader feedback
      7. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Unity Networking – The Pong Game
      1. Introducing multiplayer games
      2. Introducing UDP communication
      3. Setting up the Master Server
      4. NetworkViews and state serialization
      5. Writing a custom state serializer
      6. Using RPCs
      7. Initializing a server
      8. Connecting to a server
      9. Connecting to the Master Server
      10. Registering a server with the Master Server
      11. Browsing available servers
      12. Setting up a dedicated server model
        1. Servers in Unity
        2. Compiler directives
          1. Setting up a server console without Pro
      13. Loading networked levels
      14. Creating a multiplayer Pong game
        1. Preparing the Field
        2. The Ball script
        3. The Paddle script
        4. Keeping score
        5. Displaying the score to the player
        6. Networking the game
        7. Spawning paddles
        8. The networked ball
        9. Networked scorekeeping
        10. The Connect screen
      15. Summary
    9. 2. Photon Unity Networking – The Chat Client
      1. Differences between PUN and Unity Networking
      2. Setting up PUN with Photon Cloud
      3. Using PhotonViews
      4. Connecting to Photon and getting a list of rooms
      5. Creating and joining rooms
        1. Creating rooms
        2. Joining rooms
      6. Filtering results by user preference
        1. Filtering arrays
        2. Filtering and caching a room list
      7. Automatic matchmaking
      8. Finding friends
      9. Syncing a level between players
      10. Creating a chat client
        1. The Connect screen
        2. The Lobby screen
        3. The chat room
          1. Adding friends lists
      11. Summary
    10. 3. Photon Server – Star Collector
      1. Dedicated servers
      2. Getting the Photon Server
      3. Creating a server application
        1. Creating a class library
        2. Responding to operation requests
        3. Deploying the server code
      4. Connecting from Unity and passing messages
      5. Creating a game logic class
      6. Assigning player IDs
      7. Building a star collector game
        1. Preparing the class library
        2. The Actor class
        3. Sending an ID to a player
        4. Keeping track of the game state
        5. Spawning and picking up stars
        6. Broadcasting events
        7. Connecting from Unity
        8. Creating/destroying actors
          1. Controlling the player
      8. Summary
    11. 4. Player.IO – Bot Wars
      1. Player.IO versus the Photon Server
      2. Getting and setting up a development server
      3. Setting up the Unity client SDK
      4. Connecting to Player.IO
      5. Getting a list of rooms
        1. Connecting to rooms
      6. Creating rooms
      7. Random matchmaking
      8. Sending/receiving messages
        1. Server-side code
      9. Working with BigDB
      10. Creating a simple RTS prototype
        1. The server-side code
        2. The client-side code
      11. Summary
    12. 5. PubNub – The Global Chatbox
      1. Overview of PubNub
      2. Getting started
      3. How PubNub works
      4. Parsing JSON from PubNub
      5. Building a PubNub interface
      6. Creating a global chatbox application
        1. Publishing chat messages
        2. Displaying chat logs
      7. Summary
    13. 6. Entity Interpolation and Prediction
      1. Entity interpolation
      2. The client-side prediction
      3. Rigidbody simulation
      4. Creating a networked object
      5. Adding naive interpolation
      6. Improving interpolation
      7. Preparing for server authoritative movement
      8. Implementing server authoritative movement
      9. Notes on hacking
      10. Summary
    14. 7. Server-side Hit Detection
      1. Client-side versus server-side hit detection
      2. Creating a testbed
      3. Moving hit detection to the server
      4. Entity rewinding
      5. Summary
    15. Index

Product information

  • Title: Unity Multiplayer Games
  • Author(s): Alan Stagner
  • Release date: December 2013
  • Publisher(s): Packt Publishing
  • ISBN: 9781849692328