为什么保存后插件连接信号不起作用?

发布于 2025-01-10 16:03:19 字数 1058 浏览 2 评论 0原文

我创建了一个插件,当我打开项目时它工作正常,但是当我自打开以来第一次按 ctrl + s 保存场景时,插件上的按钮(Close_btn in在这种情况下)停止工作

tool
extends EditorPlugin

var Key_Btn=null;
var UI=load("res://addons/Plugin_Name/UI.tscn").instance();

func show_UI():
    get_editor_interface().add_child(UI)

func close_UI():
    if(get_editor_interface().has_node(UI.name)):
        get_editor_interface().remove_child(UI);


func _enter_tree():
    
    Key_Btn=Button.new();
    Key_Btn.text=" Key ";
    Key_Btn.flat=true;
    add_control_to_container(CONTAINER_CANVAS_EDITOR_MENU,Key_Btn)
    Key_Btn.connect("pressed",self,"show_UI")
    

func _exit_tree():
    close_UI();
    remove_control_from_container(CONTAINER_CANVAS_EDITOR_MENU,Key_Btn)

这就是插件按钮的样子:
输入图片这里的描述

按下按钮时弹出的UI: 输入图片此处描述

我该如何解决这个问题?

I've created a plugin and it works fine when I open the project but as soon as I press ctrl + s to save the scene for the first time since opening, the buttons on the plugin (Close_btn in this case) stop working

tool
extends EditorPlugin

var Key_Btn=null;
var UI=load("res://addons/Plugin_Name/UI.tscn").instance();

func show_UI():
    get_editor_interface().add_child(UI)

func close_UI():
    if(get_editor_interface().has_node(UI.name)):
        get_editor_interface().remove_child(UI);


func _enter_tree():
    
    Key_Btn=Button.new();
    Key_Btn.text=" Key ";
    Key_Btn.flat=true;
    add_control_to_container(CONTAINER_CANVAS_EDITOR_MENU,Key_Btn)
    Key_Btn.connect("pressed",self,"show_UI")
    

func _exit_tree():
    close_UI();
    remove_control_from_container(CONTAINER_CANVAS_EDITOR_MENU,Key_Btn)

This is what the plugin button looks like:
enter image description here

The UI that pops up when you press the button:
enter image description here

How do I solve this?

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

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

发布评论

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

评论(1

泪意 2025-01-17 16:03:19

我试过你的代码。我确实修改了 UI,如下所述。但是,对于您的代码,UI 或打开它的按钮在任何时候都不会停止工作。

这就是我尝试过的(在测试之间关闭和打开项目):

  • 保存,然后打开 UI。然后关闭 UI 并再次打开。
  • 打开 UI,然后关闭它,然后保存,然后再次打开它。
  • 打开 UI,在打开 UI 的情况下保存,关闭它,然后再次打开它。

我在 Godot 3.3、3.4、3.4.3 和 3.5 beta 1 上进行了测试。


因为您有一个名为“透明背景”的 Button。我将其设置为“完整矩形”,并设置其 self_modulate 的 alpha 使其透明。因此,它不会让我与编辑器中的任何内容进行交互……

为了能够关闭 UI,我必须向 Control Main 添加一个脚本,如下所示:

tool
extends Control

func close():
    if is_inside_tree():
        get_parent().remove_child(self)

不要忘记创建一个工具脚本。< /em>

我将来自透明背景和 Close_btn 的新闻信号连接到我添加的 close 方法。

另一种方法是从 UI 发出信号,并在 EditorPlugin 上将其连接到 close_UI…我没有这样做是因为我不想更改你的代码。由于这一切都适用于该代码,所以我可以说您的问题不是该代码。


还要注意,您在 初始化时加载 UI 场景的实例>编辑器插件。因此......

对该场景的一些修改不会反映在 EditorPlugin 上,直到您再次禁用并启用它,或再次加载项目。

我说“一些修改”,因为您会看到反映了加载时对其资源的修改。比如我可以修改我附加的脚本,或者重新导入纹理等等。 但是,如果我用新资源替换该资源,我将在已加载的 UI 上看到旧资源。

考虑到这一点,我尝试修改我附加的脚本引入错误并保存...并且 UI 仍然出现。不过,由于我附加的脚本不起作用,我无法关闭 UI,因此我必须完全关闭 Godot。

事实上,我能够使按钮在保存后停止工作的唯一方法是在 EditorPlugin 代码中引入错误并保存。我只能假设这就是发生在你身上的事情。

I tried your code. I did modify the UI as I describe below. However, with your code, at no point the UI or the button to open it stopped working.

This is what I tried (closing and opening the project between tests):

  • Saving, then opening the UI. Then closing the UI and opening it again.
  • Opening the UI, then closing it, then saving, then opening it again.
  • Opening the UI, saving with the UI open, closing it, then opening it again.

I tested on Godot 3.3, 3.4,, 3.4.3 and 3.5 beta 1.


Since you have a Button called Transparent Background. I had it set to Full Rect, and set the alpha of its self_modulate to make it transparent. Consequently it won't let me interact with anything in the editor…

To be able to close the UI, I had to add a script to Control Main that looks like this:

tool
extends Control

func close():
    if is_inside_tree():
        get_parent().remove_child(self)

Don't forget to make a tool script.

And I connected the press signal from the Transparent Background and Close_btn to the close method I added.

An alternative would have been to emit a signal from the UI and on the EditorPlugin have it connected to close_UI… I didn't do that because I didn't want to change your code. And since it all worked with that code, I can say that issue for you is not that code.


Also be aware that you load an instance the UI scene on the initialization of your EditorPlugin. In consequence…

Some modifications to that scene won't be reflected on the EditorPlugin until you disable and enable it again, or load the project again.

And I say "some modifications", because you will see reflected the modifications to the resources it had when loaded. For example, I can modify the script I attached, or re-import texture, and so on. However, if I replace the resource with a new one, I will see the old resource on the already loaded UI.

With that in mind, I tried modifying the script I attached to introduce an error and saved… And the UI still appears. Except, since the script I attached was not working, I could not close the UI, so I had to close Godot altogether.

In fact, the only way I have been able to make the button stop working after saving was by introducing an error in the EditorPlugin code and saving. I can only assume this is what happened to you.

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