unity new networking system...

Post on 25-Jul-2018

224 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

Remote Client Server

Relay Server

Status - Platforms

Planned Core Launch Platforms:

Coming Soon Platforms:

Windows Mac

Android Linux

iOS Web player

Xbox One PS4

WebGL* Window Store Apps (Windows 10)

Multiplayer System Components

Transport Layer

Engine Components

C# HLAPI Editor

Integration

Online Services

Network System is a set of components that work together:

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

• 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 Functionality

Transport / Configuration

Connection / Reader / Writer

NetworkIdentity / NetworkBehaviour

NetworkScene / ClientScene

NetworkManager

NetworkLobbyManager

Layers of Network HLAPI Functionality

Low Level API

Messaging & Serialization

Connection Management NetworkClient / NetworkServer

Object state & Actions

Object Life-Cycle

Game Control

Player Control

NetworkTransform NetworkAnimator

NetworkProximityChecker

Engine Integration

LLAPI

• 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

Transport / Configuration

Messaging & Serialization

• 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 / Reader / Writer

Connection Management

• Client connects to a server

• Server manages connections from many clients

• Callbacks for Network Events:

– Connect

– Disconnect

– Errors

NetworkClient / NetworkServer

Object State & Networked Actions

• 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

NetworkIdentity / NetworkBehaviour

Object Life Cycle

• 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()

NetworkScene / ClientScene

Game Control

• 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

NetworkManager

Player Control

• 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

NetworkLobbyManager

Network Lobby - GUI

• 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

NetworkLobbyManager

Network Lobby - GUI

Engine Integration

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.

NetworkTransform NetworkAnimator

NetworkProximityChecker

Network Profiler

• Two new profiler panels:

– Network Messaging

– Network Operations

– Currently in development (unfinished)

To understand Messaging panel, need to understand messaging.

TCP/IP

Network Stack Comparison

IP TCP Messaging Buffered Stream Application

UDP

IP UDP Unreliable Messaging Application

UNet

IP UDP

Messaging

LLAPI Channels & Messaging

Application HLAPI

Buffered Messaging

(kernel)

(kernel)

(kernel) (C++) (C#)

High Level API Message Buffering

User Script

Network Connection

Channel Buffers

Network Transport

SendBytes()

Buffered Messages

UDP Protocol Packet

UNet HLAPI

SyncVar Update

(HLAPI C#)

(C++)

Network

Unbuffered Messages

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-new-

unity-multiplayer-technology/

• UNET Transport Layer Blog – http://blogs.unity3d.com/2014/06/11/all-about-the-unity-

networking-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 (seanr@unity3d.com) – Erik Juhl (erikj@unity3d.com)

Questions?

top related