Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

EditorScenePostImport

继承: RefCounted < Object

导入后对场景进行后处理。

描述

通过将自定义脚本导入属性设置为从此类继承的 tool 脚本,可以在导入后立即自动修改导入的场景。

_post_import 回调接收导入场景的根节点,并返回场景的修改版本。使用示例:

@tool # 需要它才能在编辑器中运行。
extends EditorScenePostImport

# 该示例更改所有节点名称。
# 在导入场景并获取根节点后立即调用。
func _post_import(scene):
    # 将所有节点名称更改为 “modified_[oldnodename]”
    iterate(scene)
    return scene # 记得返回导入的场景

func iterate(node):
    if node != null:
        node.name = "modified_" + node.name
        for child in node.get_children():
            iterate(child)

教程

方法

Object

_post_import ( Node scene ) virtual

String

get_source_file ( ) const


方法说明

Object _post_import ( Node scene ) virtual

在场景被导入后触发。本方法必须返回场景的修改版本。


String get_source_file ( ) const

返回导入的源文件路径(如res://scene.dae)。