EditorScenePostImport

继承: RefCounted < Object

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

描述

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

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

GDScriptC#

  1. @tool # 需要它才能在编辑器中运行。
  2. extends EditorScenePostImport
  3. # 该示例更改所有节点名称。
  4. # 在导入场景并获取根节点后立即调用。
  5. func _post_import(scene):
  6. # 将所有节点名称更改为 “modified_[oldnodename]”
  7. iterate(scene)
  8. return scene # 记得返回导入的场景
  9. func iterate(node):
  10. if node != null:
  11. node.name = "modified_" + node.name
  12. for child in node.get_children():
  13. iterate(child)
  1. using Godot;
  2. // 该示例更改所有节点名称。
  3. // 在导入场景并获取根节点后立即调用。
  4. [Tool]
  5. public partial class NodeRenamer : EditorScenePostImport
  6. {
  7. public override GodotObject _PostImport(Node scene)
  8. {
  9. // 将所有节点名称更改为 “modified_[oldnodename]”
  10. Iterate(scene);
  11. return scene; // 记得返回导入的场景
  12. }
  13. public void Iterate(Node node)
  14. {
  15. if (node != null)
  16. {
  17. node.Name = $"modified_{node.Name}";
  18. foreach (Node child in node.GetChildren())
  19. {
  20. Iterate(child);
  21. }
  22. }
  23. }
  24. }

教程

方法

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)。

Previous Next


© 版权所有 2014-present Juan Linietsky, Ariel Manzur and the Godot community (CC BY 3.0). Revision b1c660f7.

Built with Sphinx using a theme provided by Read the Docs.