为什么保存后插件连接信号不起作用?
我创建了一个插件,当我打开项目时它工作正常,但是当我自打开以来第一次按 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)
我该如何解决这个问题?
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:
The UI that pops up when you press the button:
How do I solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我试过你的代码。我确实修改了 UI,如下所述。但是,对于您的代码,UI 或打开它的按钮在任何时候都不会停止工作。
这就是我尝试过的(在测试之间关闭和打开项目):
我在 Godot 3.3、3.4、3.4.3 和 3.5 beta 1 上进行了测试。
因为您有一个名为“透明背景”的
Button
。我将其设置为“完整矩形”,并设置其self_modulate
的 alpha 使其透明。因此,它不会让我与编辑器中的任何内容进行交互……为了能够关闭 UI,我必须向 Control Main 添加一个脚本,如下所示:
不要忘记创建一个工具脚本。< /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):
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 itsself_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:
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 theEditorPlugin
have it connected toclose_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 yourEditorPlugin
. 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.