Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

功能标签

前言

Godot 有一个特殊的系统来标记功能的可用性。每个功能均表示为一个字符串,可以引用以下各项:

  • 平台名称。

  • 平台架构(64 位或 32 位,x86 或 ARM)。

  • 平台类型(桌面、移动、Web)。

  • 平台上支持的纹理压缩算法。

  • 构建是 debug 还是 releasedebug 包括编辑器)。

  • 项目是从编辑器运行还是从“独立”二进制文件运行。

  • 其他更多的东西。

Features can be queried at runtime from the singleton API by calling:

OS.has_feature(name)

GDExtension 使用操作系统功能标签(OS feature tag)来确定要加载的库。例如,标记为 linux.debug.editor.x86_64 的库将仅在 Linux x86_64 的调试编辑器版本上加载。

默认功能

这是 Godot 中大多数功能标签的列表。请注意它们是区分大小写的:

功能标签

描述

android

在 Android 上运行(非 Web 浏览器)

bsd

在 *BSD 上运行(非 Web 浏览器)

linux

在 Linux 上运行(非 Web 浏览器)

macos

在 macOS 上运行(非 Web 浏览器)

ios

在 iOS 上运行(非 Web 浏览器)

windows

在 Windows 上运行

linuxbsd

在 Linux 或 *BSD 上运行

debug

在调试版本上运行(包括编辑器)

release

在发布版本上运行

editor

在编辑器构建上运行

template

在非编辑器(导出模板)构建上运行

double

在双精度构建上运行

single

在单精度构建上运行

64

在 64 位构建上运行(不限架构)

32

在 32 位构建上运行(不限架构)

x86_64

在 64 位 x86 架构构建上运行

x86_32

在 32 位 x86 架构构建上运行

x86

在 x86 构建上运行(不限位数)

arm64

在 64 位 ARM 架构构建上运行

arm32

在 32 位 ARM 架构构建上运行

arm

在 ARM 架构构建上运行(不限位数)

rv64

在 64 位 RISC-V 构建上运行

riscv

在 RISC-V 构建上运行(不限位数)

ppc64

在 64 位 PowerPC 构建上运行

ppc32

在 32 位 PowerPC 构建上运行

ppc

在 PowerPC 构建上运行(不限位数)

wasm64

在 64 位 WebAssembly 构建上运行(尚不支持)

wasm32

在 32 位 WebAssembly 构建上运行

wasm

在 WebAssembly 构建上运行(不限位数)

mobile

宿主操作系统是移动平台

pc

宿主操作系统是 PC 平台(台式机/笔记本电脑)

web

宿主操作系统是网页浏览器

web_android

宿主操作系统是运行在 Android 系统上的网页浏览器

web_ios

宿主操作系统是运行在 iOS 上的网页浏览器

web_linuxbsd

宿主操作系统是运行在 Linux 或 *BSD 系统上的网页浏览器

web_macos

宿主操作系统是运行在 macOS 上的网页浏览器

web_windows

宿主操作系统是运行在 Windows 系统上的网页浏览器

etc

支持使用 ETC1 压缩的纹理

etc2

支持使用 ETC2 压缩的纹理

s3tc

支持使用 S3TC(DXT/BC)压缩的纹理

movie

Movie Maker 模式已激活

警告

With the exception of texture compression, web_<platform> and movie feature tags, default feature tags are immutable. This means that they will not change depending on runtime conditions. For example, OS.has_feature("mobile") will return false when running a project exported to Web on a mobile device.

To check whether a project exported to Web is running on a mobile device, use OS.has_feature("web_android") or OS.has_feature("web_ios").

自定义功能

可以向构建添加自定义功能;使用导出预设中用于生成它的相关字段:

../../_images/feature_tags1.webp

备注

自定义特性标签只会在运行导出后的项目中使用(包括 一键部署)。从编辑器中运行项目时不会使用,即便标记为可执行的导出预设对应的平台上存在自定义特性标签。

覆盖项目设置

功能可用于覆盖项目设置中的特定配置值。这样可以在构建时更好地定制任意配置。

在下面的示例中,为游戏的演示版本添加了一个不同的图标(在特定的导出预设中进行了自定义,而该预设仅包含演示关卡)。

The Project Settings panel

The desired configuration is selected, which effectively copies its properties to the panel above (1). The "demo_build" feature tag is selected (2). The configuration is added to the project settings (3).

After overriding, a new field is added for this specific configuration.

../../_images/feature_tags3.webp

备注

当使用项目设置的“override.cfg”功能时(与功能标签无关),记住功能标签仍然适用。因此,如果你想让它们覆盖所有平台和配置上的基本项目设置,请确保同时用所需的功能标签覆盖设置。

默认覆盖

默认情况下, 已有很多覆盖的设置;它们可以在项目设置的许多地方中找到.

../../_images/feature_tags4.webp

自定义构建

通过编写自定义 ExportPlugin ,功能标签也可以用于自定义构建过程。它们还用于指定在 GDNative 中加载和导出哪个共享库。