+ All Categories
Home > Documents > Unity New Networking System...

Unity New Networking System...

Date post: 25-Jul-2018
Category:
Upload: truongdien
View: 221 times
Download: 0 times
Share this document with a friend
37
Unity New Networking System (UNet) Unite Asia 2015
Transcript
Page 1: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

Unity New Networking System

(UNet)

Unite Asia 2015

Page 2: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 3: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 4: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 5: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 6: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 7: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

“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

Page 8: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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)

Page 9: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

Multiplayer System Components

Transport Layer

Engine Components

C# HLAPI Editor

Integration

Online Services

Network System is a set of components that work together:

Page 10: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 11: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 12: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

Editor Integration

• Custom inspectors for new components

• Components to view internal state of the network system

• Profiler integration

Page 13: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 14: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 15: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

Layers of Network Functionality

In Network HLAPI

Page 16: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

• 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

Page 17: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 18: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 19: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 20: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

Connection Management

• Client connects to a server

• Server manages connections from many clients

• Callbacks for Network Events:

– Connect

– Disconnect

– Errors

NetworkClient / NetworkServer

Page 21: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 22: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 23: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 24: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 25: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 26: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

Network Lobby - GUI

Page 27: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 28: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

Network Profiler

• Two new profiler panels:

– Network Messaging

– Network Operations

– Currently in development (unfinished)

To understand Messaging panel, need to understand messaging.

Page 29: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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#)

Page 30: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 31: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 32: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

Profiler Messaging Panel

Page 33: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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)

Page 34: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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

Page 35: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

Profiler Operations Panel

Page 36: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

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 ([email protected]) – Erik Juhl ([email protected])

Page 37: Unity New Networking System (UNet)japan.unity3d.com/unite/unite2015/files/DAY2_1700_room1_Sean.pdf · Hello •Sean Riley –Game industry developer since 1997 –Blizzard, NCSoft,

Questions?


Recommended