Files
godot-docs-l10n/classes/zh_Hant/class_resourceformatsaver.rst

119 lines
7.4 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

:github_url: hide
.. _class_ResourceFormatSaver:
ResourceFormatSaver
===================
**繼承:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
將特定資源型別保存到檔案。
.. rst-class:: classref-introduction-group
說明
----
當你從編輯器執行此操作或使用 :ref:`ResourceSaver<class_ResourceSaver>` 單例時,引擎可以節省資源。這要歸功於多個 **ResourceFormatSaver**\ ,每個都處理自己的格式並由引擎自動呼叫。
預設情況下Godot 將資源保存為 ``.tres``\ (基於文字)、\ ``.res``\ (二進位)或其他內建格式,但你可以選擇通過擴充這個類來建立自己的格式。請務必遵守記錄的返回型別和值。你應該給它一個全域類別名稱 ``class_name`` 以便它被註冊。與內建的 ResourceFormatSaver 一樣,它會在保存其識別型別的資源時自動呼叫。你也可以實作一個 :ref:`ResourceFormatLoader<class_ResourceFormatLoader>`\ 。
.. rst-class:: classref-reftable-group
方法
----
.. table::
:widths: auto
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`_get_recognized_extensions<class_ResourceFormatSaver_private_method__get_recognized_extensions>`\ (\ resource\: :ref:`Resource<class_Resource>`\ ) |virtual| |const| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`_recognize<class_ResourceFormatSaver_private_method__recognize>`\ (\ resource\: :ref:`Resource<class_Resource>`\ ) |virtual| |const| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`_recognize_path<class_ResourceFormatSaver_private_method__recognize_path>`\ (\ resource\: :ref:`Resource<class_Resource>`, path\: :ref:`String<class_String>`\ ) |virtual| |const| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`_save<class_ResourceFormatSaver_private_method__save>`\ (\ resource\: :ref:`Resource<class_Resource>`, path\: :ref:`String<class_String>`, flags\: :ref:`int<class_int>`\ ) |virtual| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`_set_uid<class_ResourceFormatSaver_private_method__set_uid>`\ (\ path\: :ref:`String<class_String>`, uid\: :ref:`int<class_int>`\ ) |virtual| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
方法說明
--------
.. _class_ResourceFormatSaver_private_method__get_recognized_extensions:
.. rst-class:: classref-method
:ref:`PackedStringArray<class_PackedStringArray>` **_get_recognized_extensions**\ (\ resource\: :ref:`Resource<class_Resource>`\ ) |virtual| |const| :ref:`🔗<class_ResourceFormatSaver_private_method__get_recognized_extensions>`
返回可用於保存資源對象的副檔名列表,前提是該資源物件已被識別(見 :ref:`_recognize()<class_ResourceFormatSaver_private_method__recognize>`\ )。
.. rst-class:: classref-item-separator
----
.. _class_ResourceFormatSaver_private_method__recognize:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **_recognize**\ (\ resource\: :ref:`Resource<class_Resource>`\ ) |virtual| |const| :ref:`🔗<class_ResourceFormatSaver_private_method__recognize>`
返回此保存程式能否保存給定的資源物件。
.. rst-class:: classref-item-separator
----
.. _class_ResourceFormatSaver_private_method__recognize_path:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **_recognize_path**\ (\ resource\: :ref:`Resource<class_Resource>`, path\: :ref:`String<class_String>`\ ) |virtual| |const| :ref:`🔗<class_ResourceFormatSaver_private_method__recognize_path>`
如果該saver可以處理給定的保存路徑則返回\ ``true``\ ,否則返回\ ``false``\ 。
如果未實作該方法,則預設行為是檢查路徑的副檔名是否在\ :ref:`_get_recognized_extensions()<class_ResourceFormatSaver_private_method__get_recognized_extensions>`\ 提供的範圍內。
.. rst-class:: classref-item-separator
----
.. _class_ResourceFormatSaver_private_method__save:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **_save**\ (\ resource\: :ref:`Resource<class_Resource>`, path\: :ref:`String<class_String>`, flags\: :ref:`int<class_int>`\ ) |virtual| :ref:`🔗<class_ResourceFormatSaver_private_method__save>`
將給定的資源物件保存到目標\ ``path``\ 中的檔中。 ``flags``\ 是一個位掩碼,由\ :ref:`SaverFlags<enum_ResourceSaver_SaverFlags>`\ 常數組成。
成功時返回\ :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>`\ ,失敗時返回\ :ref:`Error<enum_@GlobalScope_Error>`\ 常數。
.. rst-class:: classref-item-separator
----
.. _class_ResourceFormatSaver_private_method__set_uid:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **_set_uid**\ (\ path\: :ref:`String<class_String>`, uid\: :ref:`int<class_int>`\ ) |virtual| :ref:`🔗<class_ResourceFormatSaver_private_method__set_uid>`
為給定 ``path`` 處的資源設定新的 UID。成功時返回 :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>`\ ,失敗時返回 :ref:`Error<enum_@GlobalScope_Error>` 常數。
.. |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 (無回傳值。)`