Godot 获取editor camera的hack方法
Godot中想要自己制作editor plugin的话,可能你需要获取编辑器相机参数,现在API并未提供接口,所以只能用比较hack的方式获取。代码如下
func get_editor_camera(camera_index):#get camera in the spatial editor(4 camera in spatial editor)
var e = get_editor_interface().get_editor_viewport()
var cam = e.get_child(1).get_child(1).get_child(3).get_child(0).get_child(cam_index).get_child(0).get_child(0).get_camera()
# If the function not work, use code below to check(new version godot change the camera hierarchy)
var root = e.get_parent()
var all_nodes = []
var c = root.get_children()
while !c.empty():
var child_list = []
for i in c:
child_list += i.get_children()
all_nodes += child_list
c = child_list
for node in all_nodes:
if node.get_class() == "Camera":
print(node.transform)
print(node.get_path())
for i in range(deep):
node = node.get_parent()
print(node.get_class() + str(node.get_index()))
print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
return cam
Comments
Post a Comment