本例复刻SwiftGodot
社区的教程:Meet SwiftGodot
, 工具版本信息:
- Godot 4.2.x
- Swift 5.10
- 基于Swift的GDExtension插件
- 执行自定义逻辑
- 暴露节点属性
- 发送信号
- 链接其他节点的信号
- 多平台导出
- Windows
- MacOS
使用SwiftGodot
需要先编译我们的插件为动态库,再向Godot Editor
声明我们的动态库。
我这里以MacOS
为例进行说明,Linux
,Windows
平台的开发流程相似。
将我们的插件编译为debug
与release
两种版本,debug
库用于调试,release
库用于追踪的游戏使用。
cd SimpleRunnerDriver
# Compile the Swift code in debug mode
# This mode is easy to debug, but it comes with a performance penalty
swift build -c debug
# Compile the Swift code in release mode
swift build -c release
编译好的产物位于SimpleRunnerDriver/.build/debug
与SimpleRunnerDriver/.build/release
,我们需要使用的是两个动态库:
libSimpleRunnerDriver.dylib
:我们实际编写的插件libSwiftGodot.dylib
:我们插件所依赖的godot绑定 动态库的目标位置需要与gdextension文件的编写相对应,关于gdextension的更多内容请参考该文档。
现在我们需要编写gdextension
文件
本例中只实际使用了Windows x86_64
,MacOS arm64
两个平台的动态库
注意:Windows平台下处理已上两个库,还需要
C:\{your_swift_install_dir}\Swift\runtime-development\usr\bin\*.dll
下其他*.dll
[configuration]
entry_symbol = "swift_entry_point"
compatibility_minimum = 4.2
[libraries]
macos.debug = "res://bin/arm64-apple-macosx-debug/libSimpleRunnerDriver.dylib"
macos.release = "res://bin/arm64-apple-macosx-release/libSimpleRunnerDriver.dylib"
windows.debug.x86_32 = "res://bin/MyFirstGame"
windows.release.x86_32 = "res://bin/MyFirstGame"
windows.debug.x86_64 = "res://bin/x86_64-windows-debug"
windows.release.x86_64 = "res://bin/x86_64-windows-release"
linux.debug.x86_64 = "res://bin/MyFirstGame"
linux.release.x86_64 = "res://bin/MyFirstGame"
linux.debug.arm64 = "res://bin/MyFirstGame"
linux.release.arm64 = "res://bin/MyFirstGame"
linux.debug.rv64 = "res://bin/MyFirstGame"
linux.release.rv64 = "res://bin/MyFirstGame"
android.debug.x86_64 = "res://bin/MyFirstGame"
android.release.x86_64 = "res://bin/MyFirstGame"
android.debug.arm64 = "res://bin/MyFirstGame"
android.release.arm64 = "res://bin/MyFirstGame"
[dependencies]
macos.debug = {"res://bin/arm64-apple-macosx-debug/libSwiftGodot.dylib" : ""}
macos.release = {"res://bin/arm64-apple-macosx-release/libSwiftGodot.dylib" : ""}
windows.debug.x86_64 = {"res://bin/x86_64-windows-debug/libSwiftGodot.dll" : ""}
windows.release.x86_64 = {"res://bin/x86_64-windows-release/libSwiftGodot.dll" : ""}
此刻我们就可以回到Godot
,添加节点时可以搜索到MainLevel
,PlayerController
两个节点了