哪个 AnimationPlayer 当前显示在底部面板动画中?
Which AnimationPlayer is currently shown in bottom panel Animation?
我正在尝试创建自己的插件,我需要弄清楚哪个 AnimationPlayer
节点当前显示在底部动画面板中
并且请不要建议我使用 get_selection()
因为即使我 select 多个(或 none )AnimationPlayer
个节点,也只会显示一个动画面板
到目前为止,我的方法是尝试使用 get_editor_interface()
找到动画面板的节点,然后可能会查看它的属性?
编辑
根据用户@Theraot 给出的答案,我尝试了这个:
tool
extends EditorPlugin
func handles(object):
print('handles=>',object);
return true;
func edit(object):
print('edit=>',object);
func _enter_tree():
pass;
但是使用它我只能得到树中的 selected 节点但即使我没有 selected 任何 AnimationPlayer
节点它仍然显示在动画面板中
在你的 EditorPlugin
上实现 handles
到 return true
在给它的任何 AnimationPlayer
上,Godot 应该调用 edit
当前要编辑的AnimationPlayer
。
示例代码:
tool
extends EditorPlugin
var edited_animation_player:AnimationPlayer
func handles(object:Object) -> bool:
return object is AnimationPlayer
func edit(object:Object) -> void:
edited_animation_player = object
print(edited_animation_player)
I was hoping the information of which AnimationPlayer
is currently being edited in the Animation panel was perhaps stored in some node for the bottom panel?
即使从接口获取正确的节点:
var control:= Control.new()
var animation_player_editor:Control
add_control_to_bottom_panel(control, "puff")
for sibling in control.get_parent().get_children():
if (sibling as Control).get_class() == "AnimationPlayerEditor":
animation_player_editor = sibling
remove_control_from_bottom_panel(control)
if animation_player_editor != null:
print(animation_player_editor)
它正在编辑的 AnimationPlayer
没有暴露给脚本。我们可以在source code and a get_state
method also in the source code, but we could only access them from C++, as they are not bound for scripting (source code).
中找到一个get_player
方法
理论上我们应该能够获取 EditorPlugin
并对其调用 get_state
,但是它对我不起作用:
var animation_player_editor_plugin:EditorPlugin
for sibling in get_parent().get_children():
if (sibling as Node).get_class() == "AnimationPlayerEditorPlugin":
animation_player_editor_plugin = sibling
if animation_player_editor_plugin != null:
print(animation_player_editor_plugin.call("get_state"))
尽管 get_state
在 EditorPlugin
上公开,但似乎无法调用它。
顺便说一下,我们可以在 AnimationPlayerEditorPlugin
的 source code 中看到它遵循我上面使用的 handles
和 edit
逻辑。
我正在尝试创建自己的插件,我需要弄清楚哪个 AnimationPlayer
节点当前显示在底部动画面板中
并且请不要建议我使用 get_selection()
因为即使我 select 多个(或 none )AnimationPlayer
个节点,也只会显示一个动画面板
到目前为止,我的方法是尝试使用 get_editor_interface()
找到动画面板的节点,然后可能会查看它的属性?
编辑
根据用户@Theraot 给出的答案,我尝试了这个:
tool
extends EditorPlugin
func handles(object):
print('handles=>',object);
return true;
func edit(object):
print('edit=>',object);
func _enter_tree():
pass;
但是使用它我只能得到树中的 selected 节点但即使我没有 selected 任何 AnimationPlayer
节点它仍然显示在动画面板中
在你的 EditorPlugin
上实现 handles
到 return true
在给它的任何 AnimationPlayer
上,Godot 应该调用 edit
当前要编辑的AnimationPlayer
。
示例代码:
tool
extends EditorPlugin
var edited_animation_player:AnimationPlayer
func handles(object:Object) -> bool:
return object is AnimationPlayer
func edit(object:Object) -> void:
edited_animation_player = object
print(edited_animation_player)
I was hoping the information of which
AnimationPlayer
is currently being edited in the Animation panel was perhaps stored in some node for the bottom panel?
即使从接口获取正确的节点:
var control:= Control.new()
var animation_player_editor:Control
add_control_to_bottom_panel(control, "puff")
for sibling in control.get_parent().get_children():
if (sibling as Control).get_class() == "AnimationPlayerEditor":
animation_player_editor = sibling
remove_control_from_bottom_panel(control)
if animation_player_editor != null:
print(animation_player_editor)
它正在编辑的 AnimationPlayer
没有暴露给脚本。我们可以在source code and a get_state
method also in the source code, but we could only access them from C++, as they are not bound for scripting (source code).
get_player
方法
理论上我们应该能够获取 EditorPlugin
并对其调用 get_state
,但是它对我不起作用:
var animation_player_editor_plugin:EditorPlugin
for sibling in get_parent().get_children():
if (sibling as Node).get_class() == "AnimationPlayerEditorPlugin":
animation_player_editor_plugin = sibling
if animation_player_editor_plugin != null:
print(animation_player_editor_plugin.call("get_state"))
尽管 get_state
在 EditorPlugin
上公开,但似乎无法调用它。
顺便说一下,我们可以在 AnimationPlayerEditorPlugin
的 source code 中看到它遵循我上面使用的 handles
和 edit
逻辑。