- Network类的变量及函数
- NetworkPeerType网络连接类型
- 网络存取方式
1. Network类的变量及函数
Network类的变量
属性名 | 描述 |
---|---|
connections | 返回连接的玩家数组,数组类型是NetworkPlayer |
isClient | 判断是否为客户端 |
isServer | 判读是否为服务端 |
peerType | 连接类型。包含 disconnected, connecting, server or client. |
player | 返回本地的NetworkPlayer实例 |
Network类的函数
函数名 | 描述 |
---|---|
Connect | 连接(ip 或 domain 名字)和服务器端口 |
Destroy | Destroy the object associated with this view ID across the network. |
Disconnect | 断开所有连接并且关闭所有网络接口 |
HavePublicAddress | 检查当前机器是否有公网地址 |
InitializeServer | 初始化服务器 |
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网络连接类型
属性名 | 描述 |
---|---|
Disconnected | No client connection running. Server not initialized. |
Server | Running as server. |
Client | Running as client. |
Connecting | Attempting to connect to a server. |
3. 网络存取方式
- IP/Port
- NAT
网友评论