Unity Network 網(wǎng)絡(luò)基礎(chǔ)

  • 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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容