Mirror Networking

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

Mirror Networking

Mirror Networking
• https://mirror-networking.com
• https://mirror-networking.com/docs/index.html
Mirror Networking for Unity
• Requires Unity 2018.4 LTS and Runtime .Net 4.x (default in Unity 201
9) and .Net 2.0 Compatibility is recommended
• In Mirror’s High Level API (HLAPI) system, multiplayer games include
• Server
• Dedicated server
• This is an instance of the game that only runs to act as a server.
• Host server
• The host server creates a single instance of the game (called the host), which acts as both serv
er and client.
• Client
Host server
State Synchronization
State Synchronization
• State synchronization refers to the synchronization of values such as i
ntegers, floating point numbers, strings and boolean values belonging
to scripts.
• State synchronization is done from the Server to remote clients.
• The local client does not have data serialized to it. It does not need it, because
it shares the Scene with the server.
State Synchronization
• Data is not synchronized in the opposite direction - from remote client
s to the server. To do this, you need to use Commands.
• SyncVars
• SyncLists
• SyncDictionary
• SyncHashSet
• SyncSortedSet
Sync To Owner
• It is often the case when you don't want some player data visible to ot
her players.
• In the inspector change the "Network Sync Mode" from "Observers"
(default) to "Owner" to let Mirror know to synchronize the data only
with the owning client.
Network Discovery
Network Discovery
• Suppose your are next to a friend. He starts a game in host mode and
you want to join him. How will your phone locate his?
• Finding out his IP address is not exactly intuitive or something kids ca
n do.
Network Discovery
• When your game starts, it sends a message in your current network a
sking "Is there any server available?".
• Any server within the same network will reply and provide informatio
n about how to connect to it.

• Network Discovery uses a UDP broadcast on the LAN enabling clients t


o find the running server and connect to it.
Tutorial
Ping Pong
Pong
• NetworkManager
• NetworkManagerHUD
• NetworkBehaviour
• NetworkIdentity
• NetworkTransform
• NetworkStartPosition
• NetworkingAttributes
NetworkManager object
• Setting
• Don't destroy on Load, Run in Background
• Network Info/Max connections will also be 2
• For playing Pong the maximum number of players is 2
• the properties for Offline Scene and Online Scene will stay empty
Creating the player
• PlayerObject a prefab has to be created
• containing at least a NetworkIdentity component
with Local Player Authority checked.
• The Local Player Authority allows the player to
control and modify the gameobjects propertie
s (e.g. for movement).
• The NetworkManager needs a reference to thi
s prefab, which is located in Spawn Info/Player
Prefab
• To have the player movement synchronized ov
er the network, the player prefab also contains
a NetworkTransform.
PlayerObject

You might also like