Visual Studio 2022/Code 直接运行调试 Godot4 C# 项目

Godot

1 在 Godot 创建任意 C# 脚本文件

2 在 Godot 中构筑项目

Visual Studio 2022

方法 1

3 VS打开你刚才构筑的项目, 编辑 .csproj 文件(直接点一下解决方案里的C#项目会自动打开).加入如下代码

  <PropertyGroup>
    <StartAction>Program</StartAction>
    <StartProgram>C:\Soft\Godot\Godot.exe</StartProgram>
    <StartArguments>--path $(SolutionDir) &gt; godot.log</StartArguments>
  </PropertyGroup>

其中的 C:\Soft\Godot\Godot.exe 改成自己电脑的路径

4 现在可以在 VS 中直接运行和调试 Godot 项目了.

方法 2

3 选择调试属性

4 创建可执行文件

5 填入参数

命令行参数 中的 > godot.log 是把 Godot 的输出信息(如GD.Print)记录到文本文件.
如果想在运行的时候直接看到,可以把 可执行文件 选 Godot 的 console.exe.(经测试,用console启动无法断点)

Visual Studio Code

3 Code打开你刚才构筑的项目,并打开 .vscode 文件夹

4 修改或创建 launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Play",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "C:\\Soft\\Godot\\Godot.exe",
            "args": [],
            "cwd": "${workspaceFolder}",
            "stopAtEntry": false
        }
    ]
}

注:在 "args": [] 中加入 "res://XX.tscn" 可以直接启动指定的场景

5 修改或创建 tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build",
      "command": "dotnet",
      "type": "process",
      "args": [
        "build"
      ],
      "problemMatcher": "$msCompile",
      "presentation": {
        "echo": true,
        "reveal": "silent",
        "focus": false,
        "panel": "shared",
        "showReuseMessage": true,
        "clear": false
      }
    }
  ]
}
posted @ 2023-03-12 18:52  Magian  阅读(2380)  评论(4编辑  收藏  举报