导出包、补丁、Mod

使用案例

通常,人们希望在其游戏部署后为它添加功能。

这样的例子包括……

  • 可下载内容:向游戏添加功能和内容的能力。

  • 补丁:修复已发布产品中存在的错误的能力。

  • Mod:授予其他人为自己的游戏创建内容的能力。

这些工具可帮助开发人员基于初始版本进行扩展开发。

PCK 文件概述

Godot 通过资源包实现此功能(PCK 文件,扩展名为 .pck)。

优势:

  • 增量更新/补丁

  • 提供 DLC

  • 提供 mod 支持

  • Mod 不需要公开源代码

  • 更加模块化的项目结构

  • 用户无需替换整个游戏

除第一次需要提供完整导出给用户外, 之后添加的功能或内容, 只需要使用此功能提供PCK文件给用户更新即可.

PCK 文件通常包含但不限于:

  • 脚本

  • 场景

  • 着色器

  • 模型

  • 纹理

  • 音效

  • 音乐

  • 任何其他适合导入游戏的资产

PCK文件甚至可以是一个完全不同的Godot项目, 原始游戏在运行时加载它.

生成 PCK 文件

In order to pack all resources of a project into a PCK file open the project and go to Project/Export and click on “Export PCK/Zip”. Also make sure to have an export template selected while doing so.

../../_images/export_pck.png

另一种方法是 从命令行导出. 如果输出文件以PCK或ZIP文件扩展名结尾, 则导出过程将为所选平台构建该类型的文件.

备注

如果有人希望为他们的游戏支持 mod,他们将需要其用户创建类似的导出文件。假设原始游戏需要 PCK 资源的某种结构和/或其脚本具有特定的接口,那么有两种选择……

  1. 开发人员必须公开这些预期结构/接口的文档,期望模组制作者安装 Godot 引擎,然后,在为游戏构建 Mod 内容时,这些修改者也将遵守文档中定义的 API(这样它将起作用)。用户然后将如上所述,使用 Godot 的内置导出工具来创建 PCK 文件。

  2. 开发者使用 Godot 来构建 GUI 工具,用这个工具向项目中添加特定的 API 内容。这个 Godot 工具要么是在启用了工具构建的引擎上执行,要么就必须能够访问到这种版本的邀请(一同分发,或者加入到原版游戏的文件之中)。这样这个工具就可以使用 OS.execute() 通过命令行使用 Godot 可执行文件来导出 PCK 文件。游戏本体不应该使用工具构建的引擎(出于安全考虑),所以最好将 mod 工具和游戏分开。

在运行时打开 PCK 文件

要导入PCK文件,需要使用ProjectSettings单例。下面的例子期望在游戏可执行目录中有一个 “mod.pck” 文件。该PCK文件的根目录包含一个 “mod_scene.tscn” 测试场景。

GDScriptC#

  1. func _your_function():
  2. # This could fail if, for example, mod.pck cannot be found.
  3. var success = ProjectSettings.load_resource_pack("res://mod.pck")
  4. if success:
  5. # Now one can use the assets as if they had them in the project from the start.
  6. var imported_scene = load("res://mod_scene.tscn")
  1. private void YourFunction()
  2. {
  3. // This could fail if, for example, mod.pck cannot be found.
  4. var success = ProjectSettings.LoadResourcePack("res://mod.pck");
  5. if (success)
  6. {
  7. // Now one can use the assets as if they had them in the project from the start.
  8. var importedScene = (PackedScene)ResourceLoader.Load("res://mod_scene.tscn");
  9. }
  10. }

警告

By default, if you import a file with the same file path/name as one you already have in your project, the imported one will replace it. This is something to watch out for when creating DLC or mods. You can solve this problem by using a tool that isolates mods to a specific mods subfolder. However, it is also a way of creating patches for one’s own game. A PCK file of this kind can fix the content of a previously loaded PCK.

为了退出这个行为, 把 false 作为第二个参数传递给 ProjectSettings.load_resource_pack().

备注

对于C#项目, 你必需先构建DLL并把它放在项目目录中. 然后, 在加载资源包之前, 你需要按如下方法加载它的DLL:Assembly.LoadFile("mod.dll")

总结

This tutorial explains how to add mods, patches, or DLC to a game. The most important thing is to identify how one plans to distribute future content for their game and develop a workflow that is customized for that purpose. Godot should make that process smooth regardless of which route a developer pursues.

Previous Next


© 版权所有 2014-present Juan Linietsky, Ariel Manzur and the Godot community (CC BY 3.0). Revision b1c660f7.

Built with Sphinx using a theme provided by Read the Docs.