NetworkDiscovery
Network Lobby Manager

NetworkIdentity

NetworkIdentity es un componente de Unity que está en el corazón del nuevo sistema de red. Se puede añadir a los objetos desde el elemento de menú AddComponents-> Network-> NetworkIdentity. Este componente controla la identidad de red de un objeto, y hace que el sistema de red sea consciente de ello. Esto muestra como parece el componente NetworkIdentity en un objeto:

With the server authoritative system of the Unity Network System, networked objects with NetworkIdentities must be “spawned” by the server using NetworkServer.Spawn(). This causes them to be assigned a NetworkInstanceId and be created on clients that are connected to the server.

Scene objects are treated a bit differently than dynamically instantiated objects. These objects are all present in the scene on both client and server. However, when building the game all the scene objects with network identities are disabled. When the client connects to the server the server tells the client which scene objects should be enabled and what their most up to date state information is through spawn messages. This ensures the client will not contain objects placed at now incorrect locations when they start playing, or even objects which will be deleted immediately on connection because some event removed them before the client connected. The Server Only checkbox will ensure this a particular object will not be spawned or enabled on clients.

True si este objeto es controlado por el Cliente el cual es dueño - el objeto jugador local en ese cliente tiene autoridad sobre este. Este es utilizado por otros componentes tal como NetworkTransform.

This component contains tracking information like what scene ID, network ID and asset ID the object has been assigned. The scene ID is valid in all scene objects with a NetworkIdentity component. The network ID is the ID of this particular object instance, there might be multiple objects instantiated of a particular object type and the network ID is used to identity which object, for example, a network update should be applied to. The asset ID refers to what source asset the object was instantiated from. This is used internally when an particular object prefab is spawned over the network. This information is exposed in the preview panel at the bottom of the inspector:

At runtime there is more information to display here (a disabled NetworkBehaviour is displayed non-bold):

Propiedades

Propiedad: Función:
assetId Esto identifica el prefab asociado a este objeto (para la aparición).
clientAuthorityOwner The client that has authority for this object. This will be null if no client has authority.
connectionToClient The connection associated with this NetworkIdentity. This is only valid for player objects on the server.
connectionToServer The UConnection associated with this NetworkIdentity. This is only valid for player objects on a local client.
hasAuthority Trie, si este objeto es la versión autoritaria del objeto. Por lo que puede estar en el servidor, o en el cliente con localPlayerAuthority.
isClient True, si el objeto está corriendo en un cliente.
isLocalPlayer This returns true if this object is the one that represents the player on the local machine.
isServer True, si este objeto está corriendo en el servidor, y ha sido generado.
localPlayerAuthority True si este objeto es controlado por el Cliente el cual es dueño - el objeto jugador local en ese cliente tiene autoridad sobre este. Este es utilizado por otros componentes tal como NetworkTransform.
netId Un identificador único para esta sesión de red, asignado cuando aparezca el objeto.
observers The list of client NetworkConnections that are able to see this object. This is read-only.
playerControllerId The identifier of the controller associated with this object. Only valid for player objects.
sceneId A unique identifier for networked objects in a scene. This is only populated in play-mode.
serverOnly Una bandera (flag) para hacer que este objeto no aparezca en los clientes.

Consejos

  • Pone un componente NetworkIdentity en prefabs que serán generados.
  • Un NetworkIdentity es requerido para cada objeto que está en red.
NetworkDiscovery
Network Lobby Manager