Visual Studio

Visual Studio Community微软的一个只面向 Windows 的 IDE,个人或者组织内的非商业使用是免费的。它有很多有用的功能,如内存视图、性能视图、源码控制等。

导入项目

Visual Studio需要一个解决方案文件来处理一个项目. 虽然Godot没有附带解决方案文件, 但可以使用SCons生成.

  • 导航到Godot根文件夹, 打开命令提示符或PowerShell窗口.

  • Run scons platform=windows vsproj=yes dev_build=yes to generate the solution with debug symbols.
    vsproj 参数说明要生成 Visual Studio 项目。
    dev_build 参数确保生成中包括了调试符号,允许你进行一系列操作,例如使用断点逐步执行代码。
  • 现在你可以通过双击项目根目录下的 godot.sln 或使用Visual Studio中的 打开项目或解决方案 选项来打开项目.

  • Use the Build top menu to build the project.

警告

Visual Studio must be configured with the C++ package. It can be selected in the installer:

../../../_images/vs_1_install_cpp_package.png

调试项目

Visual Studio具有强大的调试器, 允许用户检查Godot的源代码, 在代码中的特定点中断, 检查当前的执行上下文, 并对代码库进行实时修改.

You can launch the project with the debugger attached using the Debug > Start Debugging option from the top menu. However, unless you want to debug the Project Manager specifically, you'd need to configure debugging options first. This is due to the fact that when the Godot Project Manager opens a project, the initial process is terminated and the debugger gets detached.

  • To configure the launch options to use with the debugger use Project > Properties from the top menu:

../../../_images/vs_2_project_properties.png
  • Open the Debugging section and under Command Arguments add two new arguments: the -e flag opens the editor instead of the Project Manager, and the --path argument tells the executable to open the specified project (must be provided as an absolute path to the project root, not the project.godot file; if the path contains spaces be sure to pass it inside double quotation marks).

../../../_images/vs_3_debug_command_line.webp

要了解更多的命令行参数, 请参考 命令行教程 .

Even if you start the project without a debugger attached it can still be connected to the running process using Debug > Attach to Process... menu.

要检查一切是否正常,请将断点放在 main.cpp 中,然后按 F5 开始调试。

../../../_images/vs_4_debugging_main.png

如果遇到问题, 也可在 Godot 社区论坛 中寻求帮助.