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 中导入资产

要在 Godot 中导入资产,请将资产(图像文件、场景、音频文件、字体等)直接放置在项目文件夹中。有两种方法可以实现:

  • 任何文件类型:使用操作系统的文件管理器手动复制文件。

  • Godot 能够导入的文件类型:将文件从操作系统的文件管理器拖放至编辑器的“文件系统”面板。只适用于资源文件类型(即 Godot 能够导入的文件类型)。

Godot 内部会自动导入这些文件,将导入后的资源存放在隐藏的 res://.godot/imported/ 文件夹中。

这样一来,在代码中尝试访问导入后的资产就需要使用资源加载器,因为会自动考虑内部文件的存储位置。如果用 FileAccess 尝试访问导入后的资产,虽然在编辑器中是可行的,但是在导出后的项目中会失败

然而资源加载器无法访问未经导入的文件,只有 FileAccess 类可以。

更改导入参数

备注

非原生 Godot 资源类型才有导入参数。也就是说,Godot 自己的场景和资源文件格式(.tscn.scn.tres.res)在“导入”面板中没有选项可用。

要在 Godot 中更改资产的导入参数,请在“文件系统”面板中选中相关的资源:

../../_images/import_process_example.webp

参数调整完毕后,请单击重新导入。小心:如果在单击重新导入之前在“文件系统”面板中选中其他文件,那么你做出的更改就会被丢弃。单击重新导入之后,选中的参数只会对该资产生效,后续重新导入时也会生效。

同时更改多个资产的导入参数也是可能的. 只需在资源停靠面板中一起选择所有这些资产, 当重新导入时, 所暴露的参数将应用于它们.

重新导入多个资产

在进行项目时,你可能会发现有数个资产都需要修改同一个参数的情况,例如启用 mipmap,但你只想改动特定的参数。为此,请在文件系统中选择你要重新导入的资产。现在导入选项卡的每个导入参数的左边都会出现一个复选框。

../../_images/reimport_multiple.png

勾选导入资产中你想更改的参数,然后照常修改参数。最后点击“重新导入”按钮。这样就重新导入了只有选定部分参数被修改过的资产。

自动重新导入

当源资产的 MD5 校验发生变化时,Godot 将执行自动重新导入, 应用为该特定资产配置的预设.

生成的文件

导入时会在源文件的旁边生成额外的 <资产>.import 文件,包含的是导入配置。

请务必将这些文件提交进版本控制系统,因为这些文件包含了重要的元数据。

$ ls
example.png
example.png.import
project.godot

Additionally, extra assets will be present in the hidden res://.godot/imported/ folder:

$ ls .godot/imported
example.png-218a8f2b3041327d8a5756f3a245f83b.ctex
example.png-218a8f2b3041327d8a5756f3a245f83b.md5

如果此文件夹中的任何文件(或整个文件夹)被删除,则会自动重新导入资产。因此,不建议将 .godot/ 文件夹提交给版本控制系统。提交这个文件夹虽然能够缩短在另一台计算机上检出后重新导入的时间,但是需要相当多的空间和带宽。

The default version control metadata that can be generated on project creation will automatically ignore the .godot/ folder.

更改导入资源类型

Some source assets can be imported as different types of resources. For this, select the relevant type of resource desired then click Reimport:

../../_images/import_process_changing_import_type.webp

更改默认导入参数

Different types of projects might require different defaults. Changing the import options to a predefined set of options can be achieved by using the Preset... Menu. Besides some resource types offering presets, the default settings can be saved and cleared too:

../../_images/import_process_change_preset.webp

The default import parameters for a given resource type can be changed project-wide using the Import Defaults tab of the Project Settings dialog:

../../_images/import_process_import_defaults.webp

扩展阅读

This workflow takes a little time to get used to, but it enforces a more correct way to deal with resources.

可以导入的资产类型有很多。如果想要了解用法,请继续阅读: