C# Класс UnityEngine.Networking.NetworkServer

High level UNET server.

Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
AddExternalConnection ( NetworkConnection conn ) : bool

This accepts a network connection from another external source and adds it to the server.

AddPlayerForConnection ( NetworkConnection conn, GameObject player, short playerControllerId ) : bool

When an AddPlayer message handler has received a request from a player, the server calls this to associate the player object with the connection.

AddPlayerForConnection ( NetworkConnection conn, GameObject player, short playerControllerId, NetworkHash128 assetId ) : bool
BecomeHost ( NetworkClient oldClient, int port, MatchInfo matchInfo, int oldConnectionId, PeerInfoMessage peers ) : NetworkClient
ClearHandlers ( ) : void

Clear all registered callback handlers.

ClearLocalObjects ( ) : void

This clears all of the networked objects that the server is aware of. This can be required if a scene change deleted all of the objects without destroying them in the normal manner.

ClearSpawners ( ) : void

Clears all registered spawn prefab and spawn handler functions for this server.

Configure ( ConnectionConfig config, int maxConnections ) : bool

This configures the transport layer settings for the server.

Configure ( HostTopology topology ) : bool

This configures the transport layer settings for the server.

Destroy ( GameObject obj ) : void

Destroys this object and corresponding objects on all clients.

DestroyPlayersForConnection ( NetworkConnection conn ) : void

This destroys all the player objects associated with a NetworkConnections on a server.

DisconnectAll ( ) : void

Disconnect all currently connected clients.

FindLocalObject ( NetworkInstanceId netId ) : GameObject

This finds the local NetworkIdentity object with the specified network Id.

GetConnectionStats ( ) : NetworkConnection.PacketStat>.Dictionary

Gets aggregate packet stats for all connections.

GetStatsIn ( int &numMsgs, int &numBytes ) : void
GetStatsOut ( int &numMsgs, int &numBufferedMsgs, int &numBytes, int &lastBufferedPerSecond ) : void
Listen ( MatchInfo matchInfo, int listenPort ) : bool
Listen ( int serverPort ) : bool

Start the server on the given port number. Note that if a match has been created, this will listen using the Relay server instead of a local socket.

Listen ( string ipAddress, int serverPort ) : bool

Start the server on the given port number. Note that if a match has been created, this will listen using the Relay server instead of a local socket.

ListenRelay ( string relayIp, int relayPort, NetworkID netGuid, SourceID sourceId, NodeID nodeId ) : void

Starts a server using a Relay server. This is the manual way of using the Relay server, as the regular NetworkServer.Connect() will automatically use the Relay server if a match exists.

RegisterHandler ( short msgType, NetworkMessageDelegate handler ) : void

Register a handler for a particular message type.

Приватные методы

Метод Описание
ActivateLocalClientScene ( ) : void
AddExternalConnectionInternal ( NetworkConnection conn ) : bool
AddLocalClient ( LocalClient localClient ) : int
BecomeHostInternal ( NetworkClient oldClient, int port, MatchInfo matchInfo, int oldConnectionId, PeerInfoMessage peers ) : NetworkClient
CheckForNullObjects ( ) : void
CheckPlayerControllerIdForConnection ( NetworkConnection conn, short playerControllerId ) : bool
DestroyObject ( GameObject obj ) : void
DestroyObject ( NetworkIdentity uv, bool destroyServerObject ) : void
FinishPlayerForConnection ( NetworkConnection conn, NetworkIdentity uv, GameObject playerGameObject ) : void
GenerateConnectError ( int error ) : void
GenerateDataError ( NetworkConnection conn, int error ) : void
GenerateDisconnectError ( NetworkConnection conn, int error ) : void
GenerateError ( NetworkConnection conn, int error ) : void
GetNetworkIdentity ( GameObject go, NetworkIdentity &view ) : bool
HideForConnection ( NetworkIdentity uv, NetworkConnection conn ) : void
InternalAddPlayerForConnection ( NetworkConnection conn, GameObject playerGameObject, short playerControllerId ) : bool
InternalDisconnectAll ( ) : void
InternalListen ( string ipAddress, int serverPort ) : bool
InternalListenRelay ( string relayIp, int relayPort, NetworkID netGuid, SourceID sourceId, NodeID nodeId ) : void
InternalReplacePlayerForConnection ( NetworkConnection conn, GameObject playerGameObject, short playerControllerId ) : bool
InternalSetClientNotReady ( NetworkConnection conn ) : void
InternalSetMaxDelay ( float seconds ) : void
InternalUpdate ( ) : void
InvokeBytes ( ULocalConnectionToServer conn, byte buffer, int numBytes, int channelId ) : bool
InvokeHandlerOnServer ( ULocalConnectionToServer conn, short msgType, MessageBase msg, int channelId ) : bool
NetworkServer ( ) : System
OnClientReadyMessage ( NetworkMessage netMsg ) : void
OnCommandMessage ( NetworkMessage netMsg ) : void
OnConnected ( NetworkConnection conn ) : void
OnData ( NetworkConnection conn, int receivedSize, int channelId ) : void
OnDisconnected ( NetworkConnection conn ) : void
OnRemovePlayerMessage ( NetworkMessage netMsg ) : void
RegisterMessageHandlers ( ) : void

Описание методов

AddExternalConnection() публичный статический метод

This accepts a network connection from another external source and adds it to the server.

public static AddExternalConnection ( NetworkConnection conn ) : bool
conn NetworkConnection Network connection to add.
Результат bool

AddPlayerForConnection() публичный статический метод

When an AddPlayer message handler has received a request from a player, the server calls this to associate the player object with the connection.

public static AddPlayerForConnection ( NetworkConnection conn, GameObject player, short playerControllerId ) : bool
conn NetworkConnection Connection which is adding the player.
player UnityEngine.GameObject Player object spawned for the player.
playerControllerId short The player controller ID number as specified by client.
Результат bool

AddPlayerForConnection() публичный статический метод

public static AddPlayerForConnection ( NetworkConnection conn, GameObject player, short playerControllerId, NetworkHash128 assetId ) : bool
conn NetworkConnection
player UnityEngine.GameObject
playerControllerId short
assetId NetworkHash128
Результат bool

BecomeHost() публичный статический метод

public static BecomeHost ( NetworkClient oldClient, int port, MatchInfo matchInfo, int oldConnectionId, PeerInfoMessage peers ) : NetworkClient
oldClient NetworkClient
port int
matchInfo UnityEngine.Networking.Match.MatchInfo
oldConnectionId int
peers UnityEngine.Networking.NetworkSystem.PeerInfoMessage
Результат NetworkClient

ClearHandlers() публичный статический метод

Clear all registered callback handlers.

public static ClearHandlers ( ) : void
Результат void

ClearLocalObjects() публичный статический метод

This clears all of the networked objects that the server is aware of. This can be required if a scene change deleted all of the objects without destroying them in the normal manner.

public static ClearLocalObjects ( ) : void
Результат void

ClearSpawners() публичный статический метод

Clears all registered spawn prefab and spawn handler functions for this server.

public static ClearSpawners ( ) : void
Результат void

Configure() публичный статический метод

This configures the transport layer settings for the server.

public static Configure ( ConnectionConfig config, int maxConnections ) : bool
config ConnectionConfig Transport layer confuration object.
maxConnections int The maximum number of client connections to allow.
Результат bool

Configure() публичный статический метод

This configures the transport layer settings for the server.

public static Configure ( HostTopology topology ) : bool
topology HostTopology Transport layer topology object to use.
Результат bool

Destroy() публичный статический метод

Destroys this object and corresponding objects on all clients.

public static Destroy ( GameObject obj ) : void
obj UnityEngine.GameObject Game object to destroy.
Результат void

DestroyPlayersForConnection() публичный статический метод

This destroys all the player objects associated with a NetworkConnections on a server.

public static DestroyPlayersForConnection ( NetworkConnection conn ) : void
conn NetworkConnection The connections object to clean up for.
Результат void

DisconnectAll() публичный статический метод

Disconnect all currently connected clients.

public static DisconnectAll ( ) : void
Результат void

FindLocalObject() публичный статический метод

This finds the local NetworkIdentity object with the specified network Id.

public static FindLocalObject ( NetworkInstanceId netId ) : GameObject
netId NetworkInstanceId The netId of the NetworkIdentity object to find.
Результат UnityEngine.GameObject

GetConnectionStats() публичный статический метод

Gets aggregate packet stats for all connections.

public static GetConnectionStats ( ) : NetworkConnection.PacketStat>.Dictionary
Результат NetworkConnection.PacketStat>.Dictionary

GetStatsIn() публичный статический метод

public static GetStatsIn ( int &numMsgs, int &numBytes ) : void
numMsgs int
numBytes int
Результат void

GetStatsOut() публичный статический метод

public static GetStatsOut ( int &numMsgs, int &numBufferedMsgs, int &numBytes, int &lastBufferedPerSecond ) : void
numMsgs int
numBufferedMsgs int
numBytes int
lastBufferedPerSecond int
Результат void

Listen() публичный статический метод

public static Listen ( MatchInfo matchInfo, int listenPort ) : bool
matchInfo UnityEngine.Networking.Match.MatchInfo
listenPort int
Результат bool

Listen() публичный статический метод

Start the server on the given port number. Note that if a match has been created, this will listen using the Relay server instead of a local socket.

public static Listen ( int serverPort ) : bool
serverPort int Listen port number.
Результат bool

Listen() публичный статический метод

Start the server on the given port number. Note that if a match has been created, this will listen using the Relay server instead of a local socket.

public static Listen ( string ipAddress, int serverPort ) : bool
ipAddress string The IP address to bind to (optional).
serverPort int Listen port number.
Результат bool

ListenRelay() публичный статический метод

Starts a server using a Relay server. This is the manual way of using the Relay server, as the regular NetworkServer.Connect() will automatically use the Relay server if a match exists.

public static ListenRelay ( string relayIp, int relayPort, NetworkID netGuid, SourceID sourceId, NodeID nodeId ) : void
relayIp string Relay server IP Address.
relayPort int Relay server port.
netGuid NetworkID GUID of the network to create.
sourceId SourceID This server's sourceId.
nodeId NodeID The node to join the network with.
Результат void

RegisterHandler() публичный статический метод

Register a handler for a particular message type.

public static RegisterHandler ( short msgType, NetworkMessageDelegate handler ) : void
msgType short Message type number.
handler NetworkMessageDelegate Function handler which will be invoked for when this message type is received.
Результат void