是否可以使用适当的名称空间创建新的C#脚本?

发布于 2025-02-04 21:42:35 字数 290 浏览 3 评论 0 原文

我正在为Godot使用C#单声道版本,并想知道是否可以配置Godot使用名称空间。 夹/myclass.cs 创建新脚本时,

./文件

我希望名称空间为

myproject.folder

,因此创建的文件应该相似吗

using Godot;

namespace MyProject.Folder
{
    public class MyClass : Node2D { }
}

I'm using the C# Mono version for Godot and would like to know if it is possible to configure Godot to make use of namespaces. When creating a new script at

./Folder/MyClass.cs

I would expect the namespace to be

MyProject.Folder

So the created file should be similiar to

using Godot;

namespace MyProject.Folder
{
    public class MyClass : Node2D { }
}

Is that possible?

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

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

发布评论

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

评论(3

山色无中 2025-02-11 21:42:35

我认为不可能配置Godot这样做。需要明确的是,可以为脚本创建自定义模板,请参见。但是,据我所知,Godot没有提供在模板中使用文件夹路径(或其部分)的方法。

I don't think it is possible to configure Godot to do this. To be clear, it is possible to create custom templates for scripts, see Creating script templates. However, as far as I can tell Godot does not offer a way to use the folder path (or its parts) in a template.

罗罗贝儿 2025-02-11 21:42:35

我也认为不可能自动完成此操作。
但是,如果您使用的是VS代码,则可以单击类定义,然后按CTRL + Point或按LAMP图标以显示一些快速选项,并且可以选择更改名称空间为myProject.folder.folder选项。

I also don't think its possible to do this full automatically.
But if you are using vs code you can just click on the class definition and press ctrl + point or press the lamp icon to show some quick options and than you can select the change namespace to MyProject.Folder option.

like this example

云归处 2025-02-11 21:42:35

我在Vscode中制作了此片段,以基于文件夹结构生成名称空间。在此示例中,该项目的根文件夹是“我的游戏”。

"Creates a namespace": {
    "prefix": "nspace",
    "body": ["namespace MyGame${TM_DIRECTORY/.+My Game|(\\\\)(\\w)/${1:+.}${2:/upcase}/g};"

    ],
    "description": "Creates a namespace of the folders."
}

c:/somoutherFolder/my game/core/中的文件中执行此片段

将导致 namespace mygame.core;

I made this snippet in VsCode to generate a namespace based on the folder structure. In this example the root folder for the project is "My Game".

"Creates a namespace": {
    "prefix": "nspace",
    "body": ["namespace MyGame${TM_DIRECTORY/.+My Game|(\\\\)(\\w)/${1:+.}${2:/upcase}/g};"

    ],
    "description": "Creates a namespace of the folders."
}

executing this snippet in a file located in C:/SomeOtherFolder/My Game/core/

will result in namespace MyGame.Core;

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