安装
如何快速安装¶
本插件使用C#编写,同时,为了兼容gds生态,本插件也设计了gds的birdge类进行简化调用。
1. 安装Godot¶
- 安装Godot引擎,版本要求为4.3及以上(推荐4.6.2)。要求是.Net版本。
- 下载.Net运行时,版本要求为8.0及以上。(推荐8.0)
2. 下载插件¶
3. 安装插件¶
下载完成后,将插件文件夹解压到Godot项目的根目录下。你的项目结构应该看起来像这样:
project_root/
├── Godot-SWF/
│ ├── bridge/
│ | ├── GodotSwfNetBridge.cs
│ | └── godot_swf_gds_bridge.gdscript
│ ├── dlls/
│ │ ├── Godot SWF.dll
│ │ └── xxx.dll
│ └── shaders/
│ ├── xxx.gdshader
│ └── xxx.gdshaderinc
├── project.csproj
├── project.godot
└── project.sln
4.改写项目配置文件¶
打开项目配置文件project.csproj
如果您的项目中没有project.godot文件,请点击标题栏中的项目,然后依次点击工具->C#->Create C# solution。
如下图所示

方式一:AOT 发布(默认版本,安全且性能高)(推荐)¶
加入以下引用:
<Reference Include="Clipper2Lib">
<HintPath>Godot-SWF/dlls/Clipper2Lib.dll</HintPath>
</Reference>
<Reference Include="Godot SWF">
<HintPath>Godot-SWF/dlls/Godot SWF.dll</HintPath>
</Reference>
<Reference Include="LibTessDotNet">
<HintPath>Godot-SWF/dlls/LibTessDotNet.dll</HintPath>
</Reference>
<Reference Include="LibTessDotNet.Double">
<HintPath>Godot-SWF/dlls/LibTessDotNet.Double.dll</HintPath>
</Reference>
<Reference Include="SharpCompress">
<HintPath>Godot-SWF/dlls/SharpCompress.dll</HintPath>
</Reference>
<Reference Include="SwfLib">
<HintPath>Godot-SWF/dlls/SwfLib.dll</HintPath>
</Reference>
为了避免裁剪程序集,请再添加以下内容:
<TrimmerRootAssembly Include="GodotSharp" />
<TrimmerRootAssembly Include="Clipper2Lib" />
<TrimmerRootAssembly Include="Godot SWF" />
<TrimmerRootAssembly Include="LibTessDotNet" />
<TrimmerRootAssembly Include="LibTessDotNet.Double" />
<TrimmerRootAssembly Include="SharpCompress" />
<TrimmerRootAssembly Include="SwfLib" />
<TrimmerRootAssembly Include="$(TargetName)" />
现在,项目配置文件应该看起来像这样:
<Project Sdk="Godot.NET.Sdk/4.4.1">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<RootNamespace>YourProjectNamespace</RootNamespace>
<EnableDynamicLoading>true</EnableDynamicLoading>
<PublishAot>true</PublishAot>
</PropertyGroup>
<ItemGroup>
<TrimmerRootAssembly Include="GodotSharp" />
<TrimmerRootAssembly Include="Clipper2Lib" />
<TrimmerRootAssembly Include="Godot SWF" />
<TrimmerRootAssembly Include="LibTessDotNet" />
<TrimmerRootAssembly Include="LibTessDotNet.Double" />
<TrimmerRootAssembly Include="SharpCompress" />
<TrimmerRootAssembly Include="SwfLib" />
<TrimmerRootAssembly Include="$(TargetName)" />
<Reference Include="Clipper2Lib">
<HintPath>Godot-SWF/dlls/Clipper2Lib.dll</HintPath>
</Reference>
<Reference Include="Godot SWF">
<HintPath>Godot-SWF/dlls/Godot SWF.dll</HintPath>
</Reference>
<Reference Include="LibTessDotNet">
<HintPath>Godot-SWF/dlls/LibTessDotNet.dll</HintPath>
</Reference>
<Reference Include="LibTessDotNet.Double">
<HintPath>Godot-SWF/dlls/LibTessDotNet.Double.dll</HintPath>
</Reference>
<Reference Include="SharpCompress">
<HintPath>Godot-SWF/dlls/SharpCompress.dll</HintPath>
</Reference>
<Reference Include="SwfLib">
<HintPath>Godot-SWF/dlls/SwfLib.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
注意:AOT 方式可能对反射代码不友好。如果遇到兼容性问题,请改用下面的 Costura.Fody 方式。
方式二:非AOT安装(beta版,需与作者联系获取非AOT版本文件,使用 Costura.Fody对反射代码友好)¶
此方式将所有依赖 DLL 嵌入到主程序集中,导出后只生成一个 Godot Game.dll(实际文件名以您的项目名为准),适合不希望暴露依赖文件或遇到 AOT 兼容性问题的场景。为保证插件版权安全,需要您与作者联系获取非AOT版本文件。
步骤:
-
移除 AOT 相关设置
删除或注释项目文件中的<PublishAot>true</PublishAot>。 -
安装 Costura.Fody NuGet 包
在项目文件(.csproj)中添加以下PackageReference:
<ItemGroup>
<PackageReference Include="Costura.Fody" Version="5.7.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
- 添加 FodyWeavers.xml 配置文件
在项目根目录下创建FodyWeavers.xml,内容如下:
<Weavers>
<Costura>
<!-- 排除 Godot 运行时程序集,避免冲突 -->
<ExcludeAssemblies>
GodotSharp
GodotSharpEditor
Microsoft.*
System.*
</ExcludeAssemblies>
</Costura>
</Weavers>
-
保留 TrimmerRootAssembly(可选但推荐)
如果您启用了链接器,建议保留原有的<TrimmerRootAssembly>项,确保所有依赖不被剪裁。 -
编译项目
正常通过 Godot 编辑器或dotnet build编译。Costura 会在编译后自动将引用的 DLL(如Clipper2Lib.dll、SwfLib.dll等)嵌入到您的输出主 DLL 中。
最终项目文件示例(Costura 方式):
<Project Sdk="Godot.NET.Sdk/4.4.1">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<RootNamespace>YourProjectNamespace</RootNamespace>
</PropertyGroup>
<ItemGroup>
<TrimmerRootAssembly Include="GodotSharp" />
<TrimmerRootAssembly Include="Clipper2Lib" />
<TrimmerRootAssembly Include="Godot SWF" />
<TrimmerRootAssembly Include="LibTessDotNet" />
<TrimmerRootAssembly Include="LibTessDotNet.Double" />
<TrimmerRootAssembly Include="SharpCompress" />
<TrimmerRootAssembly Include="SwfLib" />
<TrimmerRootAssembly Include="$(TargetName)" />
</ItemGroup>
<ItemGroup>
<Reference Include="Clipper2Lib">
<HintPath>Godot-SWF/dlls/Clipper2Lib.dll</HintPath>
</Reference>
<Reference Include="Godot SWF">
<HintPath>Godot-SWF/dlls/Godot SWF.dll</HintPath>
</Reference>
<Reference Include="LibTessDotNet">
<HintPath>Godot-SWF/dlls/LibTessDotNet.dll</HintPath>
</Reference>
<Reference Include="LibTessDotNet.Double">
<HintPath>Godot-SWF/dlls/LibTessDotNet.Double.dll</HintPath>
</Reference>
<Reference Include="SharpCompress">
<HintPath>Godot-SWF/dlls/SharpCompress.dll</HintPath>
</Reference>
<Reference Include="SwfLib">
<HintPath>Godot-SWF/dlls/SwfLib.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Costura.Fody" Version="5.7.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
说明:
- Costura 不会嵌入原生 DLL(如果依赖包含 C++ 代码则无效)。本插件的依赖均为纯托管程序集,可正常工作。
5. 完成¶
完成以上步骤后,您应该可以正常使用Godot-SWF插件了。您可以查看文档中的示例代码和api说明。