从学习的角度最大的需求就是学习引擎底层是如何工作的,比如下面这段C#代码,我就想看看C++底层是如何加载ResourceLoader.Load<Texture2D>这段代码的,我还需要能下断点来调试它。
1 2 3 4 5 6 |
public override void _Ready() { GetNode<TextureRect>("TextureRect2").Texture = ResourceLoader.Load<Texture2D>("res://Atlas/a.png"); } |
首先需要编译引擎,这三篇是Godot官方的文档。
https://docs.godotengine.org/zh-cn/4.x/contributing/development/compiling/compiling_for_windows.html
https://docs.godotengine.org/zh-cn/4.x/contributing/development/compiling/compiling_with_dotnet.html
https://docs.godotengine.org/zh-cn/4.x/contributing/development/configuring_an_ide/visual_studio.html
文档上已经有的我就不详细说明了,主要说下文档上没有的,和我遇到的坑。我在windows环境下编译,需要安装Window PowerShell,这样脚本可以在这里执行。
在github上把godot的源码下载到本地,cd..到根目录下。
Window PowerShell中执行脚本,生成editor和生成C#胶水层代码。
1 2 3 4 5 6 |
# Build editor binary scons platform=windows target=editor module_mono_enabled=yes # Generate glue sources bin/godot.windows.editor.x86_64.mono --headless --generate-mono-glue modules/mono/glue |
接着在https://godotengine.org/download/archive/ 官网上看看最新的版本,这里要记住beta4这个字符串。
然后再源码的根目录找到version.py文件,并且修改status到上面记录的beta4
如果不做这个修改运行引擎会出现这个错误。
Could not resolve SDK “Godot.NET.Sdk”. Exactly one of the probing messages below indicates why we could not resolve the SDK. Investigate and resolve that message to correctly specify the SDK.
接着编译.net编译结果在./bin文件夹下。
1 2 3 4 |
# Build .NET assemblies ./modules/mono/build_scripts/build_assemblies.py --godot-output-dir=./bin --godot-platform=windows |
最后生成visualStudio工程
1 2 3 |
scons platform=windows vsproj=yes dev_build=yes module_mono_enabled=yes |
生成完毕后根目录下就会出现godot.sln文件,用visual studio2022打开在在属性页面配置我们自己godot工程的目录。
godot编辑器启动后可以点击运行游戏,其实会在产生一个运行的子进程,这样我们调试代码需要支持调试子进行。如下图所示,这里引入Microsoft Child Process Debugging Power Tool 插件,并且启动它。
完事后可以F5开始调试引擎了。引擎编译启动后,我们运行当前游戏,这样在左上角进程中应该能看到这两个进程。
点击游戏按钮,我们就可以一步步调试ResourceLoader.Load在C++的代码了,同时也可以调试C++编辑器里的代码。
我们终于也可以进一步学习godot引擎了。
- 本文固定链接: https://www.xuanyusong.com/archives/5152
- 转载请注明: 雨松MOMO 于 雨松MOMO程序研究院 发表