- AllocateViewID
- CloseConnection
- connections
- connectionTesterIP
- connectionTesterPort
- Connect
- DestroyPlayerObjects
- Destroy
- Disconnect
- GetAveragePing
- GetLastPing
- HavePublicAddress
- incomingPassword
- InitializeSecurity
- InitializeServer
- Instantiate
- isClient
- isMessageQueueRunning
- isServer
- logLevel
- maxConnections
- minimumAllocatableViewIDs
- natFacilitatorIP
- natFacilitatorPort
- OnConnectedToServer
- OnDisconnectedFromServer
- OnFailedToConnectToM...
- OnFailedToConnect
- OnNetworkInstantiate
- OnPlayerConnected
- OnPlayerDisconnected
- OnSerializeNetworkView
- OnServerInitialized
- peerType
- player
- proxyIP
- proxyPassword
- proxyPort
- RemoveRPCsInGroup
- RemoveRPCs
- sendRate
- SetLevelPrefix
- SetReceivingEnabled
- SetSendingEnabled
- TestConnectionNAT
- TestConnection
- time
- useProxy
Network.CloseConnection 关闭连接
static function CloseConnection (target : NetworkPlayer, sendDisconnectionNotification : bool) : void
Description描述
Close the connection to another system.
关闭与其他系统的连接。
/target/ defines which system to close the connection to. If we are a client the only possible connection to close is the server connection, if we are a server the target player will be kicked off. sendDisconnectionNotification, enables or disables notifications being sent to the other end. If disabled the connection is dropped, if not a disconnect notification is reliably sent to the remote party and there after the connection is dropped.
/target/定义连接到的目标系统将被关闭,如果我们是客户端,连接到服务器的连接将会关闭。如果我们是服务器,目标玩家将被踢掉。sendDisconnectionNotification启用或禁用通知将被发送到另一端。如果禁用,连接被丢弃,如果没有一个可靠断开通知发送给远端并且之后的连接将被丢弃。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void OnGUI() {
if (GUILayout.Button("Disconnect from server"))
if (Network.connections.Length == 1) {
Debug.Log("Disconnecting: " + Network.connections[0].ipAddress + ":" + Network.connections[0].port);
Network.CloseConnection(Network.connections[0], true);
} else
if (Network.connections.Length == 0)
Debug.Log("No one is connected");
else
if (Network.connections.Length > 1)
Debug.Log("Too many connections. Are we running a server?");
if (GUILayout.Button("Disconnect first player"))
if (Network.connections.Length > 0) {
Debug.Log("Disconnecting: " + Network.connections[0].ipAddress + ":" + Network.connections[0].port);
Network.CloseConnection(Network.connections[0], true);
}
}
}
function OnGUI() {
if (GUILayout.Button ("Disconnect from server")) {
if (Network.connections.Length == 1) {
Debug.Log("Disconnecting: "+
Network.connections[0].ipAddress+":"+Network.connections[0].port);
Network.CloseConnection(Network.connections[0], true);
} else if (Network.connections.Length == 0)
Debug.Log("No one is connected");
else if (Network.connections.Length > 1)
Debug.Log("Too many connections. Are we running a server?");
}
if (GUILayout.Button ("Disconnect first player")) {
if (Network.connections.Length > 0) {
Debug.Log("Disconnecting: "+
Network.connections[0].ipAddress+":"+Network.connections[0].port);
Network.CloseConnection(Network.connections[0], true);
}
}
}