Skip to content

Latest commit

 

History

History
75 lines (65 loc) · 3.25 KB

README_ZH.md

File metadata and controls

75 lines (65 loc) · 3.25 KB

Godot Swift GDExtension 示例

中文版,English

简介

本例复刻SwiftGodot社区的教程:Meet SwiftGodot, 工具版本信息:

  • Godot 4.2.x
  • Swift 5.10

特性

  • 基于Swift的GDExtension插件
    • 执行自定义逻辑
    • 暴露节点属性
    • 发送信号
    • 链接其他节点的信号
  • 多平台导出
    • Windows
    • MacOS

怎么使用

使用SwiftGodot需要先编译我们的插件为动态库,再向Godot Editor声明我们的动态库。 我这里以MacOS为例进行说明,Linux,Windows平台的开发流程相似。

编译

将我们的插件编译为debugrelease两种版本,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

安装动态库与gdextension文件编写

编译好的产物位于SimpleRunnerDriver/.build/debugSimpleRunnerDriver/.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两个节点了