MultiplayerSpawner
Automatically replicates spawnable nodes from the authority to other multiplayer peers.
描述
Spawnable scenes can be configured in the editor or through code (see add_spawnable_scene
).
Also supports custom node spawns through spawn
, calling spawn_function
on all peers.
Internally, MultiplayerSpawner uses MultiplayerAPI.object_configuration_add
to notify spawns passing the spawned node as the object
and itself as the configuration
, and MultiplayerAPI.object_configuration_remove
to notify despawns in a similar way.
属性
方法
void | add_spawnable_scene ( path: String ) |
void | clear_spawnable_scenes ( ) |
String | get_spawnable_scene ( index: int ) const1 |
int | get_spawnable_scene_count ( ) const1 |
Node | spawn ( data: Variant = null ) |
信号
despawned ( node: Node
)
Emitted when a spawnable scene or custom spawn was despawned by the multiplayer authority. Only called on remote peers.
spawned ( node: Node
)
Emitted when a spawnable scene or custom spawn was spawned by the multiplayer authority. Only called on remote peers.
属性说明
Callable
spawn_function
Method called on all peers when a custom spawn
is requested by the authority. Will receive the data
parameter, and should return a Node
that is not in the scene tree.
Note: The returned node should not be added to the scene with Node.add_child
. This is done automatically.
int
spawn_limit = 0
Maximum number of nodes allowed to be spawned by this spawner. Includes both spawnable scenes and custom spawns.
When set to 0
(the default), there is no limit.
NodePath
spawn_path = NodePath("")
Path to the spawn root. Spawnable scenes that are added as direct children are replicated to other peers.
方法说明
void
add_spawnable_scene ( path: String
)
Adds a scene path to spawnable scenes, making it automatically replicated from the multiplayer authority to other peers when added as children of the node pointed by spawn_path
.
void
clear_spawnable_scenes ( )
Clears all spawnable scenes. Does not despawn existing instances on remote peers.
String
get_spawnable_scene ( index: int
) const1
Returns the spawnable scene path by index.
int
get_spawnable_scene_count ( ) const1
Returns the count of spawnable scene paths.
Node
spawn ( data: Variant
= null )
Requests a custom spawn, with data
passed to spawn_function
on all peers. Returns the locally spawned node instance already inside the scene tree, and added as a child of the node pointed by spawn_path
.
Note: Spawnable scenes are spawned automatically. spawn
is only needed for custom spawns.
本方法通常需要用户覆盖才能生效。
本方法无副作用,不会修改该实例的任何成员变量。
本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。
本方法用于构造某个类型。
调用本方法无需实例,可直接使用类名进行调用。
本方法描述的是使用本类型作为左操作数的有效运算符。
这个值是由下列位标志构成位掩码的整数。
无返回值。