Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
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)
using Godot;
// 该示例更改所有节点名称。
// 在导入场景并获取根节点后立即调用。
[Tool]
public partial class NodeRenamer : EditorScenePostImport
{
public override GodotObject _PostImport(Node scene)
{
// 将所有节点名称更改为 “modified_[oldnodename]”
Iterate(scene);
return scene; // 记得返回导入的场景
}
public void Iterate(Node node)
{
if (node != null)
{
node.Name = $"modified_{node.Name}";
foreach (Node child in node.GetChildren())
{
Iterate(child);
}
}
}
}
教程¶
方法¶
_post_import(scene: Node) virtual |
|
get_source_file() const |
方法说明¶
Object _post_import(scene: Node) virtual 🔗
在场景被导入后触发。本方法必须返回场景的修改版本。
String get_source_file() const 🔗
返回导入的源文件路径(如res://scene.dae
)。