EditorScript

继承: RefCounted < Object

可用于向编辑器添加扩展函数的基本脚本。

描述

扩展此类的脚本并实现其_run()方法可以从脚本编辑器的文件>运行菜单选项(或通过按Ctrl + Shift + X)在编辑器运行时执行。这对于向i3D添加自定义编辑器内功能非常有用。对于更复杂的添加,请考虑使用EditorPlugin

注意:扩展脚本需要启用tool模式。

示例:运行以下脚本会打印“来自i3D编辑器的你好!”:

@tool
extends EditorScript

func _run():
    print("Hello from the i3D Editor!")

注意:该脚本在编辑器上下文中运行,这意味着输出显示在编辑器启动的控制台窗口(stdout)中,而不是通常的i3D 输出栏。

注意: EditorScript是RefCounted的,这意味着当没有任何引用它时,它会被销毁。这在异步操作期间可能会导致错误,因为没有对脚本的引用。

方法

void

_run() virtual

void

add_root_node(node: Item)

EditorInterface

get_editor_interface() const

Item

get_scene() const


方法说明

void _run() virtual 🔗

当使用File>Run时,编辑器会执行此方法。


void add_root_node(node: Item) 🔗

使node成为当前打开场景的根。仅当场景为空时才有效。如果node是场景实例,将创建继承场景。


EditorInterface get_editor_interface() const 🔗

已弃用: EditorInterface 是全局单例,可以使用其名称直接访问。

返回EditorInterface单例实例。


Item get_scene() const 🔗

返回已编辑(当前)场景的根Item。相当于EditorInterface.get_edited_scene_root()