在 godot 游戏引擎中使用不同的编程语言?

发布于 2025-01-15 07:41:01 字数 191 浏览 2 评论 0原文

我想将不同的编程语言绑定到Godot 游戏引擎。有关于这个主题的指导文件或视频吗?例如,这个项目是如何完成的:godot-rust。如果我能学习基础知识,我就能成功地用不同的语言工作。谢谢。

I want to bind a different programming language to the Godot game engine. Is there an instructional document or video on this topic? For example, how was this project done: godot-rust. If I can learn the basics, I can succeed in working in a different language. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

难理解 2025-01-22 07:41:01

在这个答案中,我向您展示了在 Godot 3.x 中添加语言支持的不同方法(Godot 4.0 和 GDExtension 的情况会有所不同 - 它取代了 GDNative,希望意味着更少的自定义构建),并且我提到了一些语言这些方法均得到支持。然而,这并不是一个详尽的语言列表。


首先,Godot 对 GDScript 和 Godot 的 VisualScript (以及 Godot 的着色)有官方内置支持语言及其视觉对应物(如果这些对您来说很重要)。


有几种使用C++的方法:

  • 您可以使用它来创建 GDNative 脚本(基本上是本机调用的包装器,允许您将它们用作 Godot 中的脚本)。

  • 或者您可以创建模块(这是您可以在自定义 Godot 构建中添加的静态库)。

  • 由于 Godot 源代码是 C++ 语言,因此如果您要进行自定义构建,则不必限制自己只制作模块。


在 Web 构建中,Godot 可以通过 JavaScript 类与 JavaScript 交互。但是,这种方法不允许您将 JavaScript 脚本添加到 Node 等。


还有一些语言只能在 Godot 的自定义构建中添加,目前官方支持的是 C#

还有其他非官方自定义版本为 LuaKotlinTypeScriptJavaScript 等语言提供语言绑定>(这次允许您制作脚本)。

如果您需要添加运行时,您可能会这样做。


某些语言利用 Godot 具有官方 Mono 支持的事实来支持 C#。例如,您可以通过这种方式使用 F#Clojure

他们首先添加一个 C# 项目,然后对其进行修改,使其使用另一种语言。如果您的语言已经编译为 .NET,这是可行的。


可以将其他一些语言添加为通过 GDNative 实现 PluginScript 类的插件。这是 PythonLua 的情况(再次),您可以从资源库中获取它们。

这是向 Godot 添加语言支持的最用户友好的方式,但它仅限于您可以使用 PluginScript 执行的操作。

附录: Gil Barbosa Reis,上述 Lua 绑定的作者,在存储库中保存了一篇关于其实现的文章系列(英语和葡萄牙语):godot-lua-pluginscript/extras/articles/。这可能是迄今为止最全面的教程。


其他语言是通过利用 GDNative 来添加的(它们基本上模仿了您使用 C++ 所做的事情)。这是 NimRustDHaskellGo 的情况, Swift...

这就是 godot-rust 的工作原理:使用 rust 制作本机库,然后 godot-rust 创建并添加它们,就像它们是用 C++ 制作的一样。对于任何已经有办法制作本机库的语言,这是一个不错的选择。


最后还有另一种方法来添加对某种语言的支持:从该语言到 GDScript 的转译器,可以使用也可以用 GDScript 编写的插件。 Lisp 就是这种情况。

最后一种方法主要用于特定领域的语言。

In this answer I show you the different approaches to add language support in Godot 3.x (the situation will be somewhat different with Godot 4.0 and GDExtension - which replaces GDNative and hopefully means less custom builds), and I mention some languages that are supported by each of these approaches. However, this is not an exhaustive list of the languages.


First of all, Godot has official build-in support for GDScript and Godot's VisualScript (and Godot's shading language and its visual counterpart if those counts for you).


There are a few ways to use C++:

  • You can use it to create GDNative scripts (which are basically a wrapper around native calls that allow you to use them as scripts in Godot).

  • Or you can create modules (which are static libraries you can add in a custom Godot build).

  • And since Godot source is in C++, you don't have to restrict yourself to making modules if you are making custom builds.


In web builds Godot can interface with JavaScript via the JavaScript class. However, this approach does not allow you to add JavaScript scripts to Nodes, and so on.


Then there are languages that can only be added in custom builds of Godot, which is currently the official support for C#.

There are other non-official custom builds that offer language binding for languages such as Lua, Kotlin, TypeScript and JavaScript (this time allowing you to make scripts).

If you need to add a runtime, you would probably do this.


Some language take advantage of the fact that Godot's has official Mono support in order to support C#. This way you can, for example, use F# and Clojure.

They start by adding a C# project and then modify it so it uses another language. This is viable if your language already compiles to .NET.


Some other languages can be added as plugins that implement the PluginScript class via GDNative. This is the case of Python and Lua (again) which you can get from the asset library.

This is the most user friendly way to add language support to Godot, but it is limited to what you can do with PluginScript.

Addendum: Gil Barbosa Reis, author of the aforementioned Lua bindings, has an article series about its implementation stuffed away in the repository (in English and Portugueses): godot-lua-pluginscript/extras/articles/. It is probably the most comprehensive tutorial to date.


Other languages are added by means of taking advantage of GDNative (They basically mimic what you would do with C++). This is the case of Nim, Rust, D, Haskell, Go, Swift

So that's how godot-rust works: make native libraries using rust and the godot-rust create and add them as if they were made in C++. For any language for which there are the means to make native libraries already, this is a good option.


Finally there is another way to add support for a language: a transpiler from that language to GDScript, which can be automated with an addon that might also be written in GDScript. This is the case of Lisp.

This last approach is mostly used for domain specific languages.

半世晨晓 2025-01-22 07:41:01

官方文档为您提供答案:

Godot 官方支持 GDScript 、C/C++、C#。

可以使用的一些第三方语言包括:Rust、D、Python、Nim 和 Go。

The official docs here provide your answer:

Godot officially supports GDScript, C/C++, C#.

Some 3rd party languages that can be used are: Rust, D, Python, Nim, and Go.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文