MultiplayerSpawner
自動將可出生節點從授權端複製到其他多人對等體。
說明
可出生的場景可以在編輯器中或通過程式碼配置(參閱 add_spawnable_scene())。
還支援通過在所有對等體上呼叫 spawn_function,通過 spawn() 自定義節點出生。
在內部,MultiplayerSpawner 使用 MultiplayerAPI.object_configuration_add() 來通知出生, 需將出生的節點作為 object,並將其自身作為 configuration 傳入;並使用 MultiplayerAPI.object_configuration_remove() 以類似的方式通知消失。
屬性
|
||
|
方法
void |
add_spawnable_scene(path: String) |
void |
|
get_spawnable_scene(index: int) const |
|
get_spawnable_scene_count() const |
|
訊號
Emitted when a spawnable scene or custom spawn was despawned by the multiplayer authority. Only called on remote peers.
Emitted when a spawnable scene or custom spawn was spawned by the multiplayer authority. Only called on remote peers.
屬性說明
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.
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("") 🔗
到出生的根的路徑。作為直接子節點被新增的可出生場景,會被複製到其他對等體。
方法說明
void add_spawnable_scene(path: String) 🔗
將場景路徑新增到可出生的場景中,使其在新增為 spawn_path 指向的節點的子節點時,自動從多人遊戲授權端,複製到其他對等體。
void clear_spawnable_scenes() 🔗
清除所有可生成的場景。不會在遠端對等體上消除現有實例。
String get_spawnable_scene(index: int) const 🔗
按索引返回可生成場景的路徑。
int get_spawnable_scene_count() const 🔗
返回可生成場景路徑的數量。
Node spawn(data: Variant = null) 🔗
請求進行一次自訂出生,data 將被傳遞給所有對等體的 spawn_function。返回本地出生的節點實例,該節點實例已經在場景樹中,並被新增為 spawn_path 指向的節點的子節點。
注意:可出生的場景是自動出生的。spawn() 僅在自訂出生時需要。