如何强制戈多特的纹理重新传播?

发布于 2025-02-12 05:49:33 字数 659 浏览 1 评论 0原文

我有一个sample.png在godot之外更改的文件
经过修改后,Godot恢复了一个信号,当收到该信号时
我希望重新进行该特定的sample.png文件

,我尝试了答案,但我想在脚本本身中重新插入并不是为其创建插件
(至少是我假设的)

我还尝试了 this 来自文档,但我不确定如何准确地使用它

EditorFileSystem.update_file("res://Assets/sample.png")

,所以如何实现所需的结果?

I have a sample.png file which is being changed outside godot
and after it's modified, godot recives a signal and when that signal is received
I want that specific sample.png file to be reimported

I tried this answer but I want to reimport in my script itself not create a plugin for it
(atleast that's what I'm assuming it does)

I also tried this from the documents but I'm not sure how to use it exactly

EditorFileSystem.update_file("res://Assets/sample.png")

so how do I achieve the desired result?

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

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

发布评论

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

评论(1

腻橙味 2025-02-19 05:49:34

EditorFilesystem用于插件。

您将从editorplugin中调用get_editor_interface()(如果您要制作插件,这将是您编写代码的地方)。这为您提供了一个editorInterface对象,您可以在其上调用get_resource_filesystem(),它为您提供了editorfilesystem对象。

因此,预期的用途是这样的:

extends EditorPlugin

func example() -> void:
    var editor_file_system := get_editor_interface().get_resource_filesystem()
    editor_file_system.scan_sources()
    # editor_file_system.update_file("res://icon.png")

顺便说一句,editorinterface还具有filesystem_changed信号。尽管我不知道它有多可靠。

通常您不必这样做。当您还原Godot窗口时,它将扫描为更改项目文件夹的更改。因此,您可以在进行其他工作时最小化Godot,而当您将Godot窗户返回时,它将选择变化。

实际上,唯一必须使用scanscan_sources的情况是我有一个工具脚本来编写应该导入的资源文件,我希望它立即反射。


我没有制作自定义插件,而是提醒您,该插件形成工具脚本(只要在编辑器中运行),您就可以简单地创建editorplugin对象。例如:

var ep = EditorPlugin.new()
ep.get_editor_interface().get_resource_filesystem().scan()
ep.free()

我还在我为您写的另一个答案中分享了这个示例标题“关于从工具脚本中保存资源”的标题。

The class EditorFileSystem is intended for plugins.

You would call get_editor_interface() from an EditorPlugin (which would be where you would be writing code if you were making a plugin). And that gives you an EditorInterface object, on which you can call get_resource_filesystem() which gives you an EditorFileSystem object.

So the intended use is something like this:

extends EditorPlugin

func example() -> void:
    var editor_file_system := get_editor_interface().get_resource_filesystem()
    editor_file_system.scan_sources()
    # editor_file_system.update_file("res://icon.png")

By the way, EditorInterface also has a filesystem_changed signal. Although I don't know how reliable it is.

Usually you don't have to do that. When you restore the Godot window, it will scan for changes in the project folder. So you might minimize Godot while you are working on something else and when you bring the Godot window back it will pick on the changes.

In practice, the only situations when I had to use scan or scan_sources was when I had a tool script that write a resource file which should be imported, and I wanted it to reflect right away.


Instead of making a custom plugin, I'll remind you that form a tool script (as long as it is running in the editor) you can simply create an EditorPlugin object. For example:

var ep = EditorPlugin.new()
ep.get_editor_interface().get_resource_filesystem().scan()
ep.free()

I had also shared this example in another answer I wrote for you a while back here, it is under the title "About saving resources from tool scripts".

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