Unity5.1 新的網路引擎UNET(十五) Networking 引用--中,unity5.1unet
孫廣東 2015.7.21
本節提供了與網路系統一起使用的組件的詳細資料。
3、NetworkClient
NetworkClient 是一個 HLAPI 類,管理網路連接到伺服器 — — 對應著 UNET NetworkServer。它可以用於將訊息發送到伺服器和從伺服器接收訊息。NetworkClient 還可以協助管理衍生的網路對象和 RPC 訊息和網路事件的路由。
Properties
| Property: |
Function: |
| serverIP |
The IP address of the server that this client is connected to. |
| serverPort |
The port of the server that this client is connected to. |
| 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是一個 HLAPI 類,封裝了網路連接。NetworkClient 對象具有一個NetworkConnections,和 NetworkServers 有多個NetworkConnections------來自每個用戶端。 網路連接已能發送位元組數組,或序列化的對象作為 網路訊息。
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 to. |
| playerControllers |
The set of players that have been added with AddPlayer(). |
5、NetworkIdentity
NetworkIdentity 組件是Unity 組件,它是 新網路系統的核心 。它可以被添加到對象。從-AddComponents->Network->NetworkIdentity 功能表項目 。此組件控制對象的網路標識。這表明 NetworkIdentity 組件在一個對象上如下所示:
與Unity Network System的 伺服器權威系統,網路的對象的NetworkIdentities 必須是由伺服器使用 NetworkServer.Spawn()所 “spawned” 。這會導致他們被分配NetworkInstanceId,在串連到伺服器的用戶端上建立。
情境物體比動態執行個體化對象有點區別對待。這些對象是全部 出現在用戶端和伺服器上的情境中。然而,當建設遊戲 的所有情境對象的identities 將被都禁用。當用戶端串連到伺服器時,伺服器將通知用戶端應啟用哪些情境對象 和其最新的狀態資訊是通過 spawn 訊息。這可確保用戶端將不會包含對象放置在現在不正確的位置,當他開始playing,或 甚至對象會立即被刪除串連因為一些事件中移除他們之前用戶端串連。"ServerOnly" 複選框將確保這某一特定對象不會催生了或在用戶端上啟用。
此組件包含像什麼情境 ID,網路識別碼 和 資產 ID 已指派給對象的跟蹤資訊。情境 ID 是一個在 NetworkIdentity 組件的所有情境物體中有效。網路識別碼 是此特定對象執行個體的 ID,可能有多個對象的特定物件類型的執行個體化和 網路識別碼 用於的標識的對象,例如,網路更新應適用。資產 ID 是指什麼源資產對象被執行個體化。這是內部使用,當特定對象預置被網路spawned 。此資訊被公開的預覽面板底部的Inspector:
在運行時是要在此處顯示的詳細資料 (disabled NetworkBehaviour 顯示 非粗體):
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 the 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 Lobby 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 could 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.
CloseYour name Your email Suggestion *Submit suggestion
Cancel
NetworkLobbyManager 是一種特殊的網路管理器,主要玩遊戲進入主情境之前的提供一個多層的大堂。
• 提供網路大廳的player限制
• 遊戲開始時所有玩家都是準備好了
• 玩家不能加入game-in-progress
• 支援“Couch Multiplayer”
• 可自訂的方式為玩家選擇在大廳中的選項
有兩種類型的球員與 NetworkLobbyManager 的對象:
LobbyPlayer 對象
• 對於每個玩家
• 建立用戶端串連,或player被添加時
• 持續,直到用戶端中斷連線
• 擁有準備flag和配置資料
• 處理在大廳裡的命令
• 應該使用 NetworkLobbyPlayer 組件
GamePlayer 對象
• 對於每個玩家
• 開始遊戲情境時被建立
• 重新進入大廳時被摧毀
• 處理在遊戲中命令
Properties
| Property: |
Function: |
| showLobbyGUI |
Show the legacy OnGUI controls for the lobby. |
| maxPlayers |
The maximum number of players allowed in the lobby. |
| 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 lobby. |
| gamePlayerPrefab |
The prefab to create for players when the game starts. |
| lobbyScene |
The scene to use for the lobby. |
| playScene |
The scene to use for main game play. |
Details
- LobbyPlayerPrefab 插槽應填寫,一個對象的 NetworkLobbyPlayer 組件。
- 有一個lobby manager GUI。看到多人遊戲大廳資產包。
7、Network Lobby 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 could 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.
CloseYour name Your email Suggestion *Submit suggestion
Cancel
NetworkLobbyPlayer 是 NetworkLobbyManager 用於儲存在大廳中的每個球員狀態。Properties
| Property: |
Function: |
| ShowLobbyGUI |
True to show the legacy user interface for players in the lobby. |
| slot |
The slot that this player was allocated too. Only one player can be in each lobby 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 could 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.
CloseYour name Your email Suggestion *Submit suggestion
Cancel
網路 管理器是一個更高的水平類 使您可以控制一個網路遊戲的狀態 。它提供了介面編輯器用於 ,和情境,以用於不同的網路遊戲狀態的預置控制網路的配置中。
Properties
| Property: |
Function: |
| networkPort |
The network port used to listen on and connect to. |
| networkAddress |
The network address to connect to. |
| 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 participating 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 could 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.
CloseYour name Your email Suggestion *Submit suggestion
Cancel
控制遊戲的網路狀態提供了預設的使用者介面。它還在編輯器中顯示有關網路管理器的目前狀態資訊。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 允許您查看在編輯器中,例如connections,很多細節 列出 已知的網路的對象,和啟用 玩家對象。
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。