- Network類的變量及函數(shù)
- NetworkPeerType網(wǎng)絡(luò)連接類型
- 網(wǎng)絡(luò)存取方式
1. Network類的變量及函數(shù)
Network類的變量
| 屬性名 | 描述 |
|---|---|
| connections | 返回連接的玩家數(shù)組,數(shù)組類型是NetworkPlayer |
| isClient | 判斷是否為客戶端 |
| isServer | 判讀是否為服務(wù)端 |
| peerType | 連接類型。包含 disconnected, connecting, server or client. |
| player | 返回本地的NetworkPlayer實(shí)例 |
Network類的函數(shù)
| 函數(shù)名 | 描述 |
|---|---|
| Connect | 連接(ip 或 domain 名字)和服務(wù)器端口 |
| Destroy | Destroy the object associated with this view ID across the network. |
| Disconnect | 斷開所有連接并且關(guān)閉所有網(wǎng)絡(luò)接口 |
| HavePublicAddress | 檢查當(dāng)前機(jī)器是否有公網(wǎng)地址 |
| InitializeServer | 初始化服務(wù)器 |
Messages
| 方法名 | 描述 |
|---|---|
| OnConnectedToServer | Called on the client when you have successfully connected to a server. |
| OnDisconnectedFromServer | Called on client during disconnection from server, but also on the server when the connection has disconnected. |
| OnFailedToConnect | Called on the client when a connection attempt fails for some reason. |
| OnNetworkInstantiate | Called on objects which have been network instantiated with Network.Instantiate. |
| OnPlayerConnected | Called on the server whenever a new player has successfully connected. |
| OnPlayerDisconnected | Called on the server whenever a player is disconnected from the server. |
| OnSerializeNetworkView | Used to customize synchronization of variables in a script watched by a network view. |
| OnServerInitialized | Called on the server whenever a Network.InitializeServer was invoked and has completed. |
2. NetworkPeerType網(wǎng)絡(luò)連接類型
| 屬性名 | 描述 |
|---|---|
| Disconnected | No client connection running. Server not initialized. |
| Server | Running as server. |
| Client | Running as client. |
| Connecting | Attempting to connect to a server. |
3. 網(wǎng)絡(luò)存取方式
- IP/Port
- NAT