Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

EditorExportPlugin

继承: RefCounted < Object

在导出项目时执行的脚本。

描述

EditorExportPlugin 会在用户导出项目时自动调用。它们最常见的用途是确定哪些文件应该包含在导出的项目中。对于每个插件,导出过程开始时都会调用 _export_begin,然后会为每一个导出的文件调用 _export_file

要使用 EditorExportPlugin,请先用 EditorPlugin.add_export_plugin 注册。

教程

方法

bool

_begin_customize_resources ( EditorExportPlatform platform, PackedStringArray features ) virtual const

bool

_begin_customize_scenes ( EditorExportPlatform platform, PackedStringArray features ) virtual const

Resource

_customize_resource ( Resource resource, String path ) virtual

Node

_customize_scene ( Node scene, String path ) virtual

void

_end_customize_resources ( ) virtual

void

_end_customize_scenes ( ) virtual

void

_export_begin ( PackedStringArray features, bool is_debug, String path, int flags ) virtual

void

_export_end ( ) virtual

void

_export_file ( String path, String type, PackedStringArray features ) virtual

PackedStringArray

_get_android_dependencies ( EditorExportPlatform platform, bool debug ) virtual const

PackedStringArray

_get_android_dependencies_maven_repos ( EditorExportPlatform platform, bool debug ) virtual const

PackedStringArray

_get_android_libraries ( EditorExportPlatform platform, bool debug ) virtual const

String

_get_android_manifest_activity_element_contents ( EditorExportPlatform platform, bool debug ) virtual const

String

_get_android_manifest_application_element_contents ( EditorExportPlatform platform, bool debug ) virtual const

String

_get_android_manifest_element_contents ( EditorExportPlatform platform, bool debug ) virtual const

int

_get_customization_configuration_hash ( ) virtual const

PackedStringArray

_get_export_features ( EditorExportPlatform platform, bool debug ) virtual const

String

_get_export_option_warning ( EditorExportPlatform platform, String option ) virtual const

Dictionary[]

_get_export_options ( EditorExportPlatform platform ) virtual const

String

_get_name ( ) virtual const

bool

_should_update_export_options ( EditorExportPlatform platform ) virtual const

bool

_supports_platform ( EditorExportPlatform platform ) virtual const

void

add_file ( String path, PackedByteArray file, bool remap )

void

add_ios_bundle_file ( String path )

void

add_ios_cpp_code ( String code )

void

add_ios_embedded_framework ( String path )

void

add_ios_framework ( String path )

void

add_ios_linker_flags ( String flags )

void

add_ios_plist_content ( String plist_content )

void

add_ios_project_static_lib ( String path )

void

add_macos_plugin_file ( String path )

void

add_shared_object ( String path, PackedStringArray tags, String target )

Variant

get_option ( StringName name ) const

void

skip ( )


方法说明

bool _begin_customize_resources ( EditorExportPlatform platform, PackedStringArray features ) virtual const

如果该插件将根据所使用的平台和功能自定义资源,则返回 true

启用后,_get_customization_configuration_hash_customize_resource_customize_scene 将被调用并且必须被实现。


bool _begin_customize_scenes ( EditorExportPlatform platform, PackedStringArray features ) virtual const

如果这个插件会根据所使用的平台和功能来定制场景,则返回 true。


Resource _customize_resource ( Resource resource, String path ) virtual

定制一个资源。如果对其进行了修改,则返回相同的或新的资源。否则,返回 null

path 参数只在定制一个实际文件时使用,否则这意味着这个资源是另一个资源的一部分,并且它将是空的。

如果 _begin_customize_resources 返回 true,则需要实现该方法。


Node _customize_scene ( Node scene, String path ) virtual

定制一个场景。如果对其进行了修改,则返回相同的或新的场景。否则,返回 null 。如果返回一个新的场景,则由你来处理旧的场景。

如果 _begin_customize_scenes 返回 true,则需要实现该方法。


void _end_customize_resources ( ) virtual

资源的自定义处理完成时调用。


void _end_customize_scenes ( ) virtual

场景的自定义处理完成时调用。


void _export_begin ( PackedStringArray features, bool is_debug, String path, int flags ) virtual

由用户重写的虚方法。它在导出开始时调用,并提供有关导出的所有信息。features 是导出的特性列表,is_debugtrue 时用于调试构建,path 是导出项目的目标路径。flags 仅在运行可运行配置文件时使用,例如在 Android 上使用本机运行时。


void _export_end ( ) virtual

可以被用户重写的虚方法。在导出完成后被调用。


void _export_file ( String path, String type, PackedStringArray features ) virtual

虚方法,需要用户重写。对于每个导出的文件调用,提供可用于标识文件的参数。path是文件的路径,type是文件所表示的Resource(例如PackedScene),features是导出的特性列表。

在此回调中调用skip将使文件不包含在导出中。


PackedStringArray _get_android_dependencies ( EditorExportPlatform platform, bool debug ) virtual const

由用户覆盖的虚方法。调用该函数是为了检索该插件提供的 Android 依赖项集。每个返回的 Android 依赖项应具有 Android 远程二进制依赖项的格式:org.godot.example:my-plugin:0.0.0

有关详细信息,请参阅 有关依赖项的 Android 文档

注意:仅在 Android 上受支持,并且需要启用 EditorExportPlatformAndroid.gradle_build/use_gradle_build


PackedStringArray _get_android_dependencies_maven_repos ( EditorExportPlatform platform, bool debug ) virtual const

由用户覆盖的虚方法。调用该函数是为了检索该插件提供的 Android 依赖项集的 Maven 存储库的 URL。

有关更多信息,请参阅 有关依赖管理的 Gradle 文档

注意:Google 的 Maven 存储库和 Maven Central 存储库默认已包含在内。

注意:仅在 Android 上受支持,并且需要启用 EditorExportPlatformAndroid.gradle_build/use_gradle_build


PackedStringArray _get_android_libraries ( EditorExportPlatform platform, bool debug ) virtual const

由用户覆盖的虚方法。调用该函数是为了检索该插件提供的 Android 库存档(AAR)文件的本地路径。

注意:相对路径必须相对于 Godot 的 res://addons/ 目录。例如,位于 res://addons/hello_world_plugin/HelloWorld.release.aar 下的 AAR 文件,可以使用 res://addons/hello_world_plugin/HelloWorld.release.aar 作为绝对路径,或使用 hello_world_plugin/HelloWorld.release.aar 作为相对路径返回。

注意:仅在 Android 上受支持,并且需要启用 EditorExportPlatformAndroid.gradle_build/use_gradle_build


String _get_android_manifest_activity_element_contents ( EditorExportPlatform platform, bool debug ) virtual const

由用户覆盖的虚方法。这在导出时用于更新生成的 Android 清单中的 activity 元素的内容。

注意:仅在 Android 上受支持,并且需要启用 EditorExportPlatformAndroid.gradle_build/use_gradle_build


String _get_android_manifest_application_element_contents ( EditorExportPlatform platform, bool debug ) virtual const

由用户覆盖的虚方法。这在导出时用于更新生成的 Android 清单中的 application 元素的内容。

注意:仅在 Android 上受支持,并且需要启用 EditorExportPlatformAndroid.gradle_build/use_gradle_build


String _get_android_manifest_element_contents ( EditorExportPlatform platform, bool debug ) virtual const

由用户覆盖的虚方法。这在导出时用于更新生成的 Android 清单中的 manifest 元素的内容。

注意:仅在 Android 上受支持,并且需要启用 EditorExportPlatformAndroid.gradle_build/use_gradle_build


int _get_customization_configuration_hash ( ) virtual const

根据传入的配置返回一个哈希值(对于场景和资源)。这有助于为单独的导出配置保留单独的缓存。

如果 _begin_customize_resources 返回 true,则需要实现该方法。


PackedStringArray _get_export_features ( EditorExportPlatform platform, bool debug ) virtual const

返回该预设对于给定的 platform,应该具有的附加功能的 PackedStringArray


String _get_export_option_warning ( EditorExportPlatform platform, String option ) virtual const

检查给定 option 的要求,如果不满足则返回非空警告字符串。

注意:使用 get_option 检查导出选项的值。


Dictionary[] _get_export_options ( EditorExportPlatform platform ) virtual const

返回导出选项列表,能够用来配置这个导出插件。

返回值中的每个元素都是一个 Dictionary,包含如下字段:

  • option:字典,结构与 Object.get_property_list 文档中的相同,但所有字段都是可选的。

  • default_value:该选项的默认值。

  • update_visibility:可选的布尔值。如果设为 true,则该选项发生变化时,预设会发出 Object.property_list_changed


String _get_name ( ) virtual const

返回该插件的名称标识符(供导出器将来识别)。插件在导出前按名称排序。

需要实现该方法。


bool _should_update_export_options ( EditorExportPlatform platform ) virtual const

如果 _get_export_options 的结果发生了改变,与 platform 对应的导出预设的选项需要更新,则返回 true


bool _supports_platform ( EditorExportPlatform platform ) virtual const

如果插件支持给定的 platform,则返回 true


void add_file ( String path, PackedByteArray file, bool remap )

添加一个要导出的自定义文件。path 是可以用来加载该文件的虚拟路径,file 是该文件的二进制数据。

_export_file 中调用时,如果 remaptrue,则当前文件将不会被导出,而是被重新映射到这个自定义文件。在其他地方调用时会忽略 remap


void add_ios_bundle_file ( String path )

将给定的path中的iOS bundle文件添加到导出的项目中。


void add_ios_cpp_code ( String code )

将 C++ 代码添加到 iOS 导出中。最终的代码是由每个激活的导出插件附加的代码创建的。


void add_ios_embedded_framework ( String path )

将动态库(*.dylib、*.framework)添加到 iOS 的 Xcode 项目的链接阶段,并将其嵌入到生成的二进制文件中。

注意:对于静态库(*.a),该方法的工作方式与 add_ios_framework 相同。

注意:此方法不该用于系统库,因为它们已经存在于设备上。


void add_ios_framework ( String path )

在 iOS 的 Xcode 项目中链接阶段添加静态库(*.a)或动态库(*.dylib、*.framework)。


void add_ios_linker_flags ( String flags )

为 iOS 导出添加链接器标志。


void add_ios_plist_content ( String plist_content )

为 iOS 属性列表文件添加内容。


void add_ios_project_static_lib ( String path )

向 iOS 项目中添加位于给定路径 path 的静态库。


void add_macos_plugin_file ( String path )

将匹配 path 的文件或目录,添加到 macOS 应用程序包的 PlugIns 目录中。

注意:仅适用于 macOS 导出。


void add_shared_object ( String path, PackedStringArray tags, String target )

添加一个共享对象或仅包含具有给定 tags 和目标 path 的共享对象的目录。

注意:使用 macOS 导出时,这些共享对象将被添加到应用程序包的 Frameworks 目录中。

如果使用的是目录,如果将非代码对象放在该目录中,则代码签名时会报错。


Variant get_option ( StringName name ) const

返回 _get_export_options 提供的导出选项的当前值。


void skip ( )

_export_file 中调用。跳过当前文件,因此它不包括在导出中。