MultiplayerAPI
Hereda: RefCounted < Object
Heredado por: MultiplayerAPIExtension, SceneMultiplayer
High-level multiplayer API interface.
Descripción
Base class for high-level multiplayer API implementations. See also MultiplayerPeer.
By default, SceneTree has a reference to an implementation of this class and uses it to provide multiplayer capabilities (i.e. RPCs) across the whole scene.
It is possible to override the MultiplayerAPI instance used by specific tree branches by calling the SceneTree.set_multiplayer() method, effectively allowing to run both client and server in the same scene.
It is also possible to extend or replace the default implementation via scripting or native extensions. See MultiplayerAPIExtension for details about extensions, SceneMultiplayer for the details about the default implementation.
Propiedades
Métodos
create_default_interface() static |
|
get_default_interface() static |
|
object_configuration_add(object: Object, configuration: Variant) |
|
object_configuration_remove(object: Object, configuration: Variant) |
|
poll() |
|
rpc(peer: int, object: Object, method: StringName, arguments: Array = []) |
|
void |
set_default_interface(interface_name: StringName) static |
Señales
connected_to_server() 🔗
Emitida cuando multiplayer_peer de esta MultiplayerAPI se conecta con éxito a un servidor. Solo se emite en los clientes.
connection_failed() 🔗
Emitida cuando el multiplayer_peer de esta MultiplayerAPI falla al establecer una conexión con un servidor. Solo se emite en los clientes.
Emitted when this MultiplayerAPI's multiplayer_peer connects with a new peer. ID is the peer ID of the new peer. Clients get notified when other clients connect to the same server. Upon connecting to a server, a client also receives this signal for the server (with ID being 1).
Emitted when this MultiplayerAPI's multiplayer_peer disconnects from a peer. Clients get notified when other clients disconnect from the same server.
server_disconnected() 🔗
Emitida cuando el multiplayer_peer de esta MultiplayerAPI se desconecta del servidor. Solo se emite en los clientes.
Enumeraciones
enum RPCMode: 🔗
RPCMode RPC_MODE_DISABLED = 0
Se utiliza con Node.rpc_config() para deshabilitar un método o propiedad para todas las llamadas RPC, haciéndolo no disponible. Es el valor por defecto para todos los métodos.
RPCMode RPC_MODE_ANY_PEER = 1
Used with Node.rpc_config() to set a method to be callable remotely by any peer. Analogous to the @rpc("any_peer") annotation. Calls are accepted from all remote peers, no matter if they are node's authority or not.
RPCMode RPC_MODE_AUTHORITY = 2
Used with Node.rpc_config() to set a method to be callable remotely only by the current multiplayer authority (which is the server by default). Analogous to the @rpc("authority") annotation. See Node.set_multiplayer_authority().
Descripciones de Propiedades
MultiplayerPeer multiplayer_peer 🔗
void set_multiplayer_peer(value: MultiplayerPeer)
MultiplayerPeer get_multiplayer_peer()
The peer object to handle the RPC system (effectively enabling networking when set). Depending on the peer itself, the MultiplayerAPI will become a network server (check with is_server()) and will set root node's network mode to authority, or it will become a regular client peer. All child nodes are set to inherit the network mode by default. Handling of networking-related events (connection, disconnection, new clients) is done by connecting to MultiplayerAPI's signals.
Descripciones de Métodos
MultiplayerAPI create_default_interface() static 🔗
Devuelve una nueva instancia del MultiplayerAPI predeterminado.
StringName get_default_interface() static 🔗
Devuelve el nombre de la clase de implementación predeterminada de MultiplayerAPI. Suele ser "SceneMultiplayer" cuando SceneMultiplayer está disponible. Véase set_default_interface().
PackedInt32Array get_peers() 🔗
Devuelve los ID de todos los pares conectados del multiplayer_peer de este MultiplayerAPI.
Devuelve el ID del par remitente del RPC que se está ejecutando.
Nota: Este método devuelve 0 cuando se llama fuera de un RPC. Como tal, el ID del par original puede perderse cuando la ejecución del código se retrasa (como con la palabra clave await de GDScript).
Devuelve el ID único del par del multiplayer_peer de este MultiplayerAPI.
Devuelve true si hay un multiplayer_peer establecido.
Devuelve true si el multiplayer_peer de este MultiplayerAPI es válido y está en modo servidor (escuchando las conexiones).
Error object_configuration_add(object: Object, configuration: Variant) 🔗
Notifica a la MultiplayerAPI de una nueva configuration para el object dado. Este método es usado internamente por SceneTree para configurar la ruta raíz para esta MultiplayerAPI (pasando null y un NodePath válido como configuration). Este método puede ser usado además por implementaciones de MultiplayerAPI para proveer funcionalidades adicionales, consulta la implementación específica (ej. SceneMultiplayer) para detalles de cómo lo usan.
Nota: Este método es principalmente relevante cuando se extiende o se sobrescribe el comportamiento de la MultiplayerAPI mediante MultiplayerAPIExtension.
Error object_configuration_remove(object: Object, configuration: Variant) 🔗
Notifica a la MultiplayerAPI que debe eliminar una configuration para el object dado. Este método es usado internamente por SceneTree para configurar la ruta raíz para esta MultiplayerAPI (pasando null y un NodePath vacío como configuration). Este método puede ser usado además por implementaciones de MultiplayerAPI para proveer funcionalidades adicionales, consulta la implementación específica (ej. SceneMultiplayer) para detalles de cómo lo usan.
Nota: Este método es principalmente relevante cuando se extiende o se sobrescribe el comportamiento de la MultiplayerAPI mediante MultiplayerAPIExtension.
Método utilizado para sondear la MultiplayerAPI. Solo tienes que preocuparte por esto si estableces SceneTree.multiplayer_poll a false. Por defecto, SceneTree sondeará sus MultiplayerAPI(s) por ti.
Nota: Este método resulta en llamadas RPC, por lo que se ejecutarán en el mismo contexto de esta función (ej. _process, physics, Thread).
Error rpc(peer: int, object: Object, method: StringName, arguments: Array = []) 🔗
Sends an RPC to the target peer. The given method will be called on the remote object with the provided arguments. The RPC may also be called locally depending on the implementation and RPC configuration. See Node.rpc() and Node.rpc_config().
Note: Prefer using Node.rpc(), Node.rpc_id(), or my_method.rpc(peer, arg1, arg2, ...) (in GDScript), since they are faster. This method is mostly useful in conjunction with MultiplayerAPIExtension when extending or replacing the multiplayer capabilities.
void set_default_interface(interface_name: StringName) static 🔗
Establece la clase de implementación de MultiplayerAPI por defecto. Este método puede ser usado por módulos y extensiones para configurar cuál implementación será usada por SceneTree cuando el motor se inicie.