GDScript:使用EditorScript开发简单的编辑器脚本

EditorScript可以用于开发简单的编辑器脚本
  • 它继承于Reference<Object,因此它不是挂到场景节点来执行的,可以直接通过脚本编辑器来执行它
  • 需要在tool模式下运行
范例代码
tool
#MyEditorScript.gd
extends EditorScript
func _run():
	print("hello")

在这里插入图片描述

也可以使用快捷键Control + Shift + x执行

常用方法 说明
void _run() virtual Control + Shift + x时执行
void add_root_node(node: Node) root下添加一个节点,目前版本被禁用
EditorInterface get_editor_interface() 返回EditorInterface单例对象
EditorInterface get_editor_interface() 返回当前激活的场景

小结
EditorScript适用于简单的编辑器脚本开发,如果开发复杂的编辑器脚本,需要使用EditorPlugin

发布了261 篇原创文章 · 获赞 133 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/hello_tute/article/details/103940276