是否可以使用适当的名称空间创建新的C#脚本?
我正在为Godot使用C#单声道版本,并想知道是否可以配置Godot使用名称空间。 夹/myclass.cs 创建新脚本时,
在 ./文件
我希望名称空间为
myproject.folder
,因此创建的文件应该相似吗
using Godot;
namespace MyProject.Folder
{
public class MyClass : Node2D { }
}
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为不可能配置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.
我也认为不可能自动完成此操作。
但是,如果您使用的是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.
我在Vscode中制作了此片段,以基于文件夹结构生成名称空间。在此示例中,该项目的根文件夹是“我的游戏”。
在
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".
executing this snippet in a file located in
C:/SomeOtherFolder/My Game/core/
will result in
namespace MyGame.Core;