mirror of
https://github.com/godotengine/godot-docs-l10n.git
synced 2025-12-31 09:49:22 +03:00
227 lines
9.7 KiB
ReStructuredText
227 lines
9.7 KiB
ReStructuredText
:github_url: hide
|
|
|
|
.. meta::
|
|
:keywords: network
|
|
|
|
.. _class_MultiplayerSpawner:
|
|
|
|
MultiplayerSpawner
|
|
==================
|
|
|
|
**繼承:** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
|
|
|
|
自動將可出生節點從授權端複製到其他多人對等體。
|
|
|
|
.. rst-class:: classref-introduction-group
|
|
|
|
說明
|
|
----
|
|
|
|
可出生的場景可以在編輯器中或通過程式碼配置(參閱 :ref:`add_spawnable_scene()<class_MultiplayerSpawner_method_add_spawnable_scene>`\ )。
|
|
|
|
還支援通過在所有對等體上呼叫 :ref:`spawn_function<class_MultiplayerSpawner_property_spawn_function>`\ ,通過 :ref:`spawn()<class_MultiplayerSpawner_method_spawn>` 自定義節點出生。
|
|
|
|
在內部,\ **MultiplayerSpawner** 使用 :ref:`MultiplayerAPI.object_configuration_add()<class_MultiplayerAPI_method_object_configuration_add>` 來通知出生, 需將出生的節點作為 ``object``\ ,並將其自身作為 ``configuration`` 傳入;並使用 :ref:`MultiplayerAPI.object_configuration_remove()<class_MultiplayerAPI_method_object_configuration_remove>` 以類似的方式通知消失。
|
|
|
|
.. rst-class:: classref-reftable-group
|
|
|
|
屬性
|
|
----
|
|
|
|
.. table::
|
|
:widths: auto
|
|
|
|
+---------------------------------+-------------------------------------------------------------------------+------------------+
|
|
| :ref:`Callable<class_Callable>` | :ref:`spawn_function<class_MultiplayerSpawner_property_spawn_function>` | |
|
|
+---------------------------------+-------------------------------------------------------------------------+------------------+
|
|
| :ref:`int<class_int>` | :ref:`spawn_limit<class_MultiplayerSpawner_property_spawn_limit>` | ``0`` |
|
|
+---------------------------------+-------------------------------------------------------------------------+------------------+
|
|
| :ref:`NodePath<class_NodePath>` | :ref:`spawn_path<class_MultiplayerSpawner_property_spawn_path>` | ``NodePath("")`` |
|
|
+---------------------------------+-------------------------------------------------------------------------+------------------+
|
|
|
|
.. rst-class:: classref-reftable-group
|
|
|
|
方法
|
|
----
|
|
|
|
.. table::
|
|
:widths: auto
|
|
|
|
+-----------------------------+------------------------------------------------------------------------------------------------------------------------------+
|
|
| |void| | :ref:`add_spawnable_scene<class_MultiplayerSpawner_method_add_spawnable_scene>`\ (\ path\: :ref:`String<class_String>`\ ) |
|
|
+-----------------------------+------------------------------------------------------------------------------------------------------------------------------+
|
|
| |void| | :ref:`clear_spawnable_scenes<class_MultiplayerSpawner_method_clear_spawnable_scenes>`\ (\ ) |
|
|
+-----------------------------+------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`String<class_String>` | :ref:`get_spawnable_scene<class_MultiplayerSpawner_method_get_spawnable_scene>`\ (\ index\: :ref:`int<class_int>`\ ) |const| |
|
|
+-----------------------------+------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`get_spawnable_scene_count<class_MultiplayerSpawner_method_get_spawnable_scene_count>`\ (\ ) |const| |
|
|
+-----------------------------+------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Node<class_Node>` | :ref:`spawn<class_MultiplayerSpawner_method_spawn>`\ (\ data\: :ref:`Variant<class_Variant>` = null\ ) |
|
|
+-----------------------------+------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-descriptions-group
|
|
|
|
訊號
|
|
----
|
|
|
|
.. _class_MultiplayerSpawner_signal_despawned:
|
|
|
|
.. rst-class:: classref-signal
|
|
|
|
**despawned**\ (\ node\: :ref:`Node<class_Node>`\ ) :ref:`🔗<class_MultiplayerSpawner_signal_despawned>`
|
|
|
|
Emitted when a spawnable scene or custom spawn was despawned by the multiplayer authority. Only called on remote peers.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_MultiplayerSpawner_signal_spawned:
|
|
|
|
.. rst-class:: classref-signal
|
|
|
|
**spawned**\ (\ node\: :ref:`Node<class_Node>`\ ) :ref:`🔗<class_MultiplayerSpawner_signal_spawned>`
|
|
|
|
Emitted when a spawnable scene or custom spawn was spawned by the multiplayer authority. Only called on remote peers.
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-descriptions-group
|
|
|
|
屬性說明
|
|
--------
|
|
|
|
.. _class_MultiplayerSpawner_property_spawn_function:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`Callable<class_Callable>` **spawn_function** :ref:`🔗<class_MultiplayerSpawner_property_spawn_function>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_spawn_function**\ (\ value\: :ref:`Callable<class_Callable>`\ )
|
|
- :ref:`Callable<class_Callable>` **get_spawn_function**\ (\ )
|
|
|
|
Method called on all peers when a custom :ref:`spawn()<class_MultiplayerSpawner_method_spawn>` is requested by the authority. Will receive the ``data`` parameter, and should return a :ref:`Node<class_Node>` that is not in the scene tree.
|
|
|
|
\ **Note:** The returned node should **not** be added to the scene with :ref:`Node.add_child()<class_Node_method_add_child>`. This is done automatically.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_MultiplayerSpawner_property_spawn_limit:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`int<class_int>` **spawn_limit** = ``0`` :ref:`🔗<class_MultiplayerSpawner_property_spawn_limit>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_spawn_limit**\ (\ value\: :ref:`int<class_int>`\ )
|
|
- :ref:`int<class_int>` **get_spawn_limit**\ (\ )
|
|
|
|
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.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_MultiplayerSpawner_property_spawn_path:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`NodePath<class_NodePath>` **spawn_path** = ``NodePath("")`` :ref:`🔗<class_MultiplayerSpawner_property_spawn_path>`
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- |void| **set_spawn_path**\ (\ value\: :ref:`NodePath<class_NodePath>`\ )
|
|
- :ref:`NodePath<class_NodePath>` **get_spawn_path**\ (\ )
|
|
|
|
到出生的根的路徑。作為直接子節點被新增的可出生場景,會被複製到其他對等體。
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-descriptions-group
|
|
|
|
方法說明
|
|
--------
|
|
|
|
.. _class_MultiplayerSpawner_method_add_spawnable_scene:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
|void| **add_spawnable_scene**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_MultiplayerSpawner_method_add_spawnable_scene>`
|
|
|
|
將場景路徑新增到可出生的場景中,使其在新增為 :ref:`spawn_path<class_MultiplayerSpawner_property_spawn_path>` 指向的節點的子節點時,自動從多人遊戲授權端,複製到其他對等體。
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_MultiplayerSpawner_method_clear_spawnable_scenes:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
|void| **clear_spawnable_scenes**\ (\ ) :ref:`🔗<class_MultiplayerSpawner_method_clear_spawnable_scenes>`
|
|
|
|
清除所有可生成的場景。不會在遠端對等體上消除現有實例。
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_MultiplayerSpawner_method_get_spawnable_scene:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`String<class_String>` **get_spawnable_scene**\ (\ index\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_MultiplayerSpawner_method_get_spawnable_scene>`
|
|
|
|
按索引返回可生成場景的路徑。
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_MultiplayerSpawner_method_get_spawnable_scene_count:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`int<class_int>` **get_spawnable_scene_count**\ (\ ) |const| :ref:`🔗<class_MultiplayerSpawner_method_get_spawnable_scene_count>`
|
|
|
|
返回可生成場景路徑的數量。
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_MultiplayerSpawner_method_spawn:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Node<class_Node>` **spawn**\ (\ data\: :ref:`Variant<class_Variant>` = null\ ) :ref:`🔗<class_MultiplayerSpawner_method_spawn>`
|
|
|
|
請求進行一次自訂出生,\ ``data`` 將被傳遞給所有對等體的 :ref:`spawn_function<class_MultiplayerSpawner_property_spawn_function>`\ 。返回本地出生的節點實例,該節點實例已經在場景樹中,並被新增為 :ref:`spawn_path<class_MultiplayerSpawner_property_spawn_path>` 指向的節點的子節點。
|
|
|
|
\ **注意:**\ 可出生的場景是自動出生的。\ :ref:`spawn()<class_MultiplayerSpawner_method_spawn>` 僅在自訂出生時需要。
|
|
|
|
.. |virtual| replace:: :abbr:`virtual (本方法通常需要使用者覆寫才能生效。)`
|
|
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
|
|
.. |const| replace:: :abbr:`const (本方法沒有副作用。不會修改該實例的任何成員變數。)`
|
|
.. |vararg| replace:: :abbr:`vararg (本方法除了這裡描述的參數外,還可以接受任意數量的參數。)`
|
|
.. |constructor| replace:: :abbr:`constructor (本方法用於建構一個型別。)`
|
|
.. |static| replace:: :abbr:`static (本方法無需實例即可呼叫,因此可以直接使用類別名稱呼叫。)`
|
|
.. |operator| replace:: :abbr:`operator (本方法描述將本型別作為左運算元時可用的有效運算子。)`
|
|
.. |bitfield| replace:: :abbr:`BitField (此值是由下列旗標組成的位元遮罩整數。)`
|
|
.. |void| replace:: :abbr:`void (無回傳值。)`
|