Table of Contents
Unity Multiplayer Games
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why Subscribe?
Free Access for Packt account holders
Preface
Unity IDE crash course
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Unity Networking â The Pong Game
Introducing multiplayer games
Introducing UDP communication
Setting up the Master Server
NetworkViews and state serialization
Writing a custom state serializer
Using RPCs
Initializing a server
Connecting to a server
Connecting to the Master Server
Registering a server with the Master Server
Browsing available servers
Setting up a dedicated server model
Servers in Unity
Compiler directives
Setting up a server console without Pro
Loading networked levels
Creating a multiplayer Pong game
Preparing the Field
The Ball script
The Paddle script
Keeping score
Displaying the score to the player
Networking the game
Spawning paddles
The networked ball
Networked scorekeeping
The Connect screen
Summary
2. Photon Unity Networking â The Chat Client
Differences between PUN and Unity Networking
Setting up PUN with Photon Cloud
Using PhotonViews
Connecting to Photon and getting a list of rooms
Creating and joining rooms
Creating rooms
Joining rooms
Filtering results by user preference
Filtering arrays
Filtering and caching a room list
Automatic matchmaking
Finding friends
Syncing a level between players
Creating a chat client
The Connect screen
The Lobby screen
The chat room
Adding friends lists
Summary
3. Photon Server â Star Collector
Dedicated servers
Getting the Photon Server
Creating a server application
Creating a class library
Responding to operation requests
Deploying the server code
Connecting from Unity and passing messages
Creating a game logic class
Assigning player IDs
Building a star collector game
Preparing the class library
The Actor class
Sending an ID to a player
Keeping track of the game state
Spawning and picking up stars
Broadcasting events
Connecting from Unity
Creating/destroying actors
Controlling the player
Summary
4. Player.IO â Bot Wars
Player.IO versus the Photon Server
Getting and setting up a development server
Setting up the Unity client SDK
Connecting to Player.IO
Getting a list of rooms
Connecting to rooms
Creating rooms
Random matchmaking
Sending/receiving messages
Server-side code
Working with BigDB
Creating a simple RTS prototype
The server-side code
The client-side code
Summary
5. PubNub â The Global Chatbox
Overview of PubNub
Getting started
How PubNub works
Parsing JSON from PubNub
Building a PubNub interface
Creating a global chatbox application
Publishing chat messages
Displaying chat logs
Summary
6. Entity Interpolation and Prediction
Entity interpolation
The client-side prediction
Rigidbody simulation
Creating a networked object
Adding naive interpolation
Improving interpolation
Preparing for server authoritative movement
Implementing server authoritative movement
Notes on hacking
Summary
7. Server-side Hit Detection
Client-side versus server-side hit detection
Creating a testbed
Moving hit detection to the server
Entity rewinding
Summary
Index
Copyright © 2013 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: November 2013
Production Reference: 1201113
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-84969-232-8
www.packtpub.com
Author
Alan R. Stagner
Reviewers
Clifford Champion
Fabio Ferrara
Sriram. A. S.
Acquisition Editor
Rubal Kaur
Lead Technical Editor
Madhuja Chaudhari
Technical Editors
Dipika Gaonkar
Mrunmayee Patil
Project Coordinator
Apeksha Chitnis
Proofreader
Linda Morris
Indexer
Hemangini Bari
Graphics
Abhinash Sahu
Production Coordinator
Alwin Roy
Cover Work
Alwin Roy
Alan R. Stagner is an independent developer with a passion for Unity3D game development. He was introduced to programming by his father, he sought out different ways to create games in a variety of languages. Most recently, he found the Unity game engine and was instantly hooked, and discovered his love of multiplayer game development. He has also dabbled in database and server programming from time to time, mostly involving PHP and MySQL with recent forays into ASP.NET.
Clifford Champion has a broad background in software engineering, with years of experience spanning 3D games and Internet applications, and more recently in machine learning. He holds a degree in Mathematics from UCLA. In the past, he has worked as an integration and support engineer at Havok, and also as a lead interactive media and Internet apps programmer at PlainJoe Studios.
Now, he works for zSpace (zspace.com), a hardware/software company creating highly immersive, interactive 3D displays for classrooms, industry, and entertainment. At zSpace, he is a member of the software platform team, helping to enable the holographic-like experience on a variety of game engines and platforms, including Unity. Clifford can be found on Twitter at @duckmaestro
and welcomes any discussions.
Fabio Ferrara is a game developer. He is working for Chubby Pixel, an independent game studio based in Milan, which he founded in 2012. They work thoroughly to bring to the users the best possible gaming experience. He has also collaborated for the publication of other books such as Unity iOS Essentials, Packt Publishing.
Sriram. A. S. is a software developer who is currently living in Pune, India. He works primarily in C/C++ and Java. He has been working with Unity 3D from its very early versions; and has developed codes related to its integration with features such as augmented reality, and shared them on his tech blog (http://mypersonalsoft.blogspot.com).
In his spare time, he works on a few open source software. And he also likes to experiment with various other technologies and ideas, along with his team of code passionate friendsâthe "Hobby Coders" (http://hobbycoders.com).
Support files, eBooks, discount offers, and more
You might want to visit www.packtpub.com for support files and downloads related to your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade t...