Unity5.1 new network engine UNET (15th) Networking reference -- medium, unity5.1unet
Sun Guangdong
This section provides detailed information about components used with network systems.
3. NetworkClient
NetworkClient is a HLAPI class that connects the Management Network to the server-corresponds to the UNET NetworkServer. It can be used to send messages to the server and receive messages from the server. NetworkClient can also help manage derived network objects and RPC messages and route network events.
Properties
Property: |
Function: |
ServerIP |
The IP address of the server that this client is connected. |
ServerPort |
The port of the server that this client is connected. |
Connection |
The NetworkConnection object this client is using. |
Handlers |
The set of registered message handler functions. |
NumChannels |
The number of configured NetworkTransport QoS channels. |
IsConnected |
True if the client is connected to a server. |
AllClients |
List of active network clients (static ). |
Active |
True if any network clients are active (static ). |
4. NetworkConnection
NetworkConnection is a HLAPI class that encapsulates network connections. The NetworkClient object has one NetworkConnections, and NetworkServers has multiple NetworkConnections ------ From each client. The network connection can send byte arrays or serialized objects as network messages.
Properties
Property: |
Function: |
HostId |
The NetworkTransport hostId for this connection. |
ConnectionId |
The NetworkTransport connectionId for this connection. |
IsReady |
Flag to control whether state updates are sent to this client. |
Address |
The IP address of the end-point that this connection is connected. |
PlayerControllers |
The set of players that have been added with AddPlayer (). |
5. NetworkIdentity
The NetworkIdentity component is the Unity component and is the core of the new network system. It can be added to an object. Choose-AddComponents-> Network-> NetworkIdentity. The network ID of the control object of this component. This indicates that the NetworkIdentity component is shown as follows on an object:
The NetworkIdentities of Network objects must be "spawned" by the server using NetworkServer. Spawn ". This causes them to be assigned NetworkInstanceId and created on the Client Connected to the server.
Scene objects are slightly different from dynamic instantiated objects. All these objects appear on the client and server. However, the identities of all scenario objects for game construction will be disabled. When the client is connected to the server, the server will notify the client which scenario objects and their latest status information should be enabled through spawn messages. This ensures that the client will not include the object placed in the current incorrect location, when it starts playing, or even the object will be immediately deleted from the connection because some events remove them before the client connection. The "ServerOnly" check box ensures that a specific object is not generated or enabled on the client.
This component contains the trace information such as the scenario ID, network ID, and asset ID that has been assigned to the object. The scenario ID is valid in all scenario objects of the NetworkIdentity component. Network ID is the ID of this specific object instance. There may be multiple objects of specific object type instantiation and network ID used for the identification of objects. For example, network update should apply. Asset ID refers to the source asset object that is instantiated. This is internally used when a specific object is preset by the Network spawned. Inspector at the bottom of the preview panel where this information is exposed:
The detailed information to be displayed here during running (disabled NetworkBehaviour is not in bold ):
Properties
Property: |
Function: |
NetId |
A unique identifier for this network session, assigned when spawned. |
SceneId |
A unique identifier for networked objects in a scene. This is only populated in play-mode. |
IsClient |
True if this object is running on a client. |
IsServer |
True if this object is running on the server, and has been spawned. |
HasAuthority |
True if this object is the authoritative version of the object. So either on a server, or on the client with localPlayerAuthority. |
LocalPlayerAuthority |
True if this object is controlled by the client that owns it-the local player object on that client has authority over it. This is used by other components such as NetworkTransform. |
ServerOnly |
A flag to make this object not be spawned on clients. |
AssetId |
This identifies the prefab associated with this object (for spawning ). |
PlayerControllerId |
The identifier of the controller associated with this object. Only valid for player objects. |
Observers |
The list of client NetworkConnections that are able to see this object. This is read-only. |
Hints
- Put a NetworkIdentity component on prefabs that will be spawned.
- A NetworkIdentity is required for every object that is networked.
6. Network lolobby ManagerSuggest a changeSuccess!
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseSumbission failed
For some reason your suggested change cocould not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Close Your name Your email Suggestion * Submit suggestion
Cancel
NetworkLobbyManager is a special network manager that provides a multi-level lobby before playing games in the main scenario.
• Provide player restrictions for the network Hall
• All players are ready at the beginning of the game
• Players cannot join game-in-progress
• Supports "Couch Multiplayer"
• Customizable options for players to choose in the lobby
There are two types of players and NetworkLobbyManager objects:
LobbyPlayer object
• For each player
• When a client connection or player is added
• Continuous until the client is disconnected
• Prepare flags and configuration data
• Process commands in the lobby
• The NetworkLobbyPlayer component should be used
GamePlayer object
• For each player
• Game scenario created when you start
• Destroyed when entering the hall again
• Handle commands in the game
Properties
Property: |
Function: |
ShowLobbyGUI |
Show the legacy OnGUI controls for the lolobby. |
MaxPlayers |
The maximum number of players allowed in the lolobby. |
MaxPlayersPerConnection |
The maximum number of players allowed to be added for each client connection. |
LobbyPlayerPrefab |
The prefab to create for players when they enter the lolobby. |
GamePlayerPrefab |
The prefab to create for players when the game starts. |
LobbyScene |
The scene to use for the lolobby. |
PlayScene |
The scene to use for main game play. |
Details
- The LobbyPlayerPrefab slot should be filled in, the NetworkLobbyPlayer component of an object.
- There is a lolobby manager GUI. The asset package of multiplayer game hall is displayed.
7. Network lolobby PlayerSuggest a changeSuccess!
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseSumbission failed
For some reason your suggested change cocould not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Close Your name Your email Suggestion * Submit suggestion
Cancel
NetworkLobbyPlayer is used by NetworkLobbyManager to store the status of each player in the hall. Properties
Property: |
Function: |
ShowLobbyGUI |
True to show the legacy user interface for players in the lolobby. |
Slot |
The slot that this player was allocated too. Only one player can be in each loby slot. |
ReadyToBegin |
Flag to control if the player is ready for the game to start. |
8. Network Manager UNetSuggest a changeSuccess!
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseSumbission failed
For some reason your suggested change cocould not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Close Your name Your email Suggestion * Submit suggestion
Cancel
The network manager is a higher level class that allows you to control the status of an online game. It provides an interface editor for, and scenario, to be used in the configuration of Preset Control Networks for different online game statuses.
Properties
Property: |
Function: |
NetworkPort |
The network port used to listen on and connect. |
NetworkAddress |
The network address to connect. |
DontDestroyOnLoad |
Flag to make the NetworkManager persist between scenes. |
RunInBackground |
Flag to make the player run in the background by default. |
SendPeerInfo |
Flag to have network information on all peers sent to all participant clients. |
MaxDelay |
The maximum time in seconds to delay buffered messages. |
LogLevel |
The level of network logging to write. |
PlayerPrefab |
The prefab to instantiate for players when a client connects. |
AutoCreatePlayer |
Flag to automatically add a player when a client connects. |
PlayerSpawnMethod |
How to spawn players at StartPositions. |
OfflineScene |
The scene to switch to when the network goes off-line. |
OnlineScene |
The scene to switch to when the network goes on-line. |
SpawnPrefabs |
The set of registered spawnable prefabs. |
StartPositions |
The set of NetworkStartPosition objects found in the scene. |
CustomConfig |
Flag to use custom network configuration (advanced ). |
ConnectionConfig |
Advanced custom network configuration data. |
MaxConnections |
The maximum number of connections allowed by the server. |
Channels |
The number of transport layer QoS Channels. |
SecureTunnelEndpoint |
End point for XBox Live connectivity. |
UseSimulator |
Flag to use network conditions simulation. |
SimulatedLatency |
Latency in milliseconds to add when network simulator active. |
PacketLossPercentage |
The percentage of packet loss to add when network simulator active |
MatchHost |
Matchmaker host address. |
MatchPort |
Matchmaker host port. |
9. Network Manager HUDSuggest a changeSuccess!
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseSumbission failed
For some reason your suggested change cocould not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Close Your name Your email Suggestion * Submit suggestion
Cancel
The default user interface is provided to control the game's network status. It also displays information about the current status of the network manager in the editor. Properties
Property: |
Function: |
ShowGUI |
Flag to show the default UI. |
OffsetX |
The horizontal pixel offset of the UI. |
OffsetY |
The vertical pixel offset of the UI .. |
Details
NetworkManagerHUD allows you to view known network objects and activate player objects in the editor, such as connections.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.