Server - Unity

Transcription

Server - Unity
Unity
New Networking System
(UNet)
Unite Asia 2015
Hello
• Sean Riley
– Game industry developer since 1997
– Blizzard, NCSoft, EA Origin, Metaplace
• Works on the Unity Networking Team
– I work remotely from Florida, USA
– Travel to Copenhagen regularly
– Been with Unity 1.5 years
Why? - Developer Pain
Making multiplayer games is hard. Why is this so?
1.
Making a high performance networking transport for multiplayer
gaming is technically challenging
2.
Third party networking transports can be difficult to integrate into
your Unity game and tough to use.
3.
Getting players of your multiplayer game to find each other is
difficult without creating a common place for them to go.
4.
Getting players to connect to each other over the internet is
difficult without dedicated servers
Why? – Developer Relief
New Network System provides solutions for these issues:
1. Transport Layer – High performance UDP based network
transport for Unity Multiplayer clients
2.
Low and High Level APIs – Low level API for experienced network
programmers, and an extensible and easy to use high level API
3.
Match Maker – Basic room services for games to let players find
each other
4.
Relay Server – Allows players to communicate with each other
over the internet
New Networking System Status
• Core is in the 5.1 Beta, should be released
with 5.1
• Online Services will launch soon afterwards
• Legacy network system (Raknet)
– will initially coexist with new system in 5.1
– will be deprecated in 5.1
– will be removed soon afterwards once the new
system is fully launched
Status - Phases
• Launch is focused on core networking system
• “Multiplayer Foundation”
• Most appropriate for Peer-to-Peer games
where one peer is the “Host”
• Not focused on:
– Dedicated Servers
– MMO-like services
“Server” vs “Host”
•
•
•
•
In network games have Clients and a Server
Every game must have a Server
The client that is also the server is the Host
Code for LocalClient and RemoteClient is the same
Host
Local Client
Remote Client
Relay
Server
Server
Remote Client
Status - Platforms
Planned Core Launch Platforms:
Windows
Mac
Android
iOS
Xbox One
Linux
Web player
PS4
Coming Soon Platforms:
WebGL*
Window Store Apps
(Windows 10)
Multiplayer System Components
Network System is a set of components
that work together:
Online Services
Engine
Components
C# HLAPI
Transport Layer
Editor
Integration
Transport Layer
•
•
•
•
•
High performance UDP based transport
Written in C++
Thin layer on top of sockets
Works with arrays of bytes
Channels with Quality of Service levels
– Reliable / Fragmented / StateUpdate /Unreliable
• Focused on flexibility and performance
• Exposes a C# API
– UnityEngine.Networking.NetworkTransport
New Engine Components
• NetworkIdentity
– Identifies objects across the network
– similar to old NetworkView
• NetworkBehaviour
– Script base class derived from MonoBehaviour
– Provides network functionality to user scripts
• NetworkTransform
– Handles movement synchronization
– Works with physics systems
• NetworkManager
– Connection management
– Spawning
– Configuration
Editor Integration
• Custom inspectors for new
components
• Components to view
internal state of the
network system
• Profiler integration
High Level Network API
• C# extension DLL
• UnityEngine.Networking namespace
• Provides services useful for multiplayer games
–
–
–
–
–
Message handlers
General purpose high performance serialization
Distributed object management
State synchronization
Network classes: Server, Client, Connection, etc
• Focused on ease of use and iterative development.
• HLAPI code looks like game code
Online Services
• Hosted by Unity in the cloud
• Relay Server to allow server-less internet play
– Routes traffic between players
– Avoid NAT and Firewall issues
• Matchmaking services
• Concurrent User tracking and reporting
• Client Interface:
– Web service interfaces
– C# wrapper integrated with HLAPI
Layers of Network
Functionality
In
Network HLAPI
Layers of Network Functionality
• Network system built from a series of layers
• Each layer adds more functionality
• Developers can choose to use layers at
different levels
• Developers don’t have to use all the layers,
but using all the layers gets you started quickly
• List layers, then describe in detail
Layers of Network HLAPI
Functionality
Transport / Configuration
Connection / Reader / Writer
Low Level API
Messaging & Serialization
NetworkClient / NetworkServer
Connection Management
NetworkIdentity / NetworkBehaviour
Object state & Actions
NetworkScene / ClientScene
Object Life-Cycle
NetworkManager
Game Control
NetworkLobbyManager
NetworkTransform
NetworkAnimator
NetworkProximityChecker
Player Control
Engine Integration
LLAPI
Transport / Configuration
• UDP based network transport layer
• Implemented in C++
• Supports channels with different Quality of
Service
• Exposed to C# as NetworkTransport class
• Deals with byte arrays
Messaging & Serialization
Connection / Reader / Writer
• Support to read and write C# & Unity types
• Functions to send data:
– SendBytes()
– SendWriter()
– Send(short msgId, MessageBase msg)
• Can register handler functions for message Ids
Connection Management
NetworkClient / NetworkServer
• Client connects to a server
• Server manages connections from many
clients
• Callbacks for Network Events:
– Connect
– Disconnect
– Errors
Object State & Networked Actions
NetworkIdentity / NetworkBehaviour
• Provide script API for network game programming
• Identify objects across the network
• Synchronize state of objects
– SyncVars, SyncLists
• Perform networked actions
– Commands, ClientRPCs
• Expose network context to scripts
– isServer / isClient / isLocalPlayer
Object Life Cycle
NetworkScene / ClientScene
• Manage life-cycle of distributed objects
– Create on server -> create on client
• Create instances from prefabs
• Or, customize object creation behaviour
• Contextual callbacks on scripts:
– public virtual void OnStartClient()
– public virtual void OnStartServer()
Game Control
NetworkManager
•
•
•
•
•
Higher level control of configuration
Higher level control of object create and destroy
Synchronized scene changes across server and clients
Default user interface for game control
Many callbacks for customizing game control:
–
–
–
–
OnServerConnect
OnServerSceneChanged
OnClientConnect
OnClientSceneChanged
Player Control
NetworkLobbyManager
•
•
•
•
•
Provides a network lobby with player limit
Game starts when all players are ready
Players cannot join game-in-progress
Supports “Couch Multiplayer”
Customizable way for players to choose
options while in lobby, such as
– Choose a color
– Choose a character
Network Lobby - GUI
NetworkLobbyManager
•
•
•
•
•
•
Package that provides lobby user interface
Uses new UI system
Controller, Mouse, Touch, Keyboard support
Asset Store or Standard Assets pakage
Comes with full source code and prefabs
Completely customizable
Network Lobby - GUI
Engine Integration
NetworkTransform
NetworkAnimator
NetworkProximityChecker
Components that add network functionality to
existing engine features
• NetworkTransform:
– Synchronized movement
• NetworkAnimator:
– Synchronized animation
• NetworkProximityChecker:
– Controls object visibility (networked culling)
• Optional to use, built with public APIs.
Network Profiler
• Two new profiler panels:
– Network Messaging
– Network Operations
– Currently in development (unfinished)
To understand Messaging panel, need to understand
messaging.
Network Stack Comparison
UDP
(kernel)
IP
UDP Unreliable Messaging
TCP/IP
(kernel)
IP
TCP Messaging
(kernel)
IP
Application
(C++)
UDP
Messaging
Buffered Stream
UNet
LLAPI
Channels &
Messaging
Application
(C#)
HLAPI
Buffered
Messaging
Application
High Level API Message Buffering
User Script
UNet HLAPI
SyncVar Update
SendBytes()
Unbuffered Messages
Network Connection
(HLAPI C#)
Channel Buffers
Buffered Messages
Network Transport
(C++)
UDP Protocol Packet
Network
Profiler Messaging Panel
• Tracks message statistics
– Unbuffered Messages from Application to HLAPI
– Buffered Messages from HLAPI to LLAPI Transport
– Protocol Packets from Transport to Network
Profiler Messaging Panel
Profiler Operations Panel
• Tracks Higher level network operations
– Commands (client to server)
– ClientRPCs (server to client)
– SyncVar and SyncList state updates
– User Messages
– Object Create (server to client)
– Object Destroy (server to client)
Profiler Operations Panel
Details tracking of each type of operation:
Operation Type
Detail
Example
[Command]
[ClientRpc]
Operation Name
CmdShoot
Object Create
Object Destroy
Prefab Name or
AssetId
“Missile”
Baf67afabefab755
[SyncVar]
SyncList
Custom Serialization
Script Name
“TankCombat”
User Messages
Message ID
1003
Profiler Operations Panel
References
• UNET Announcement Blog
– http://blogs.unity3d.com/2014/05/12/announcing-unet-newunity-multiplayer-technology/
• UNET Transport Layer Blog
– http://blogs.unity3d.com/2014/06/11/all-about-the-unitynetworking-transport-layer/
• UNET SyncVar Blog
– http://blogs.unity3d.com/2014/05/29/unet-syncvar/
• UNET Unite 2014 Presentation
– https://www.youtube.com/watch?v=ywbdVTRe-aA
• Contact Information
– Sean Riley ([email protected])
– Erik Juhl ([email protected])
Questions?