class_editorscenepostimport.rst 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the EditorScenePostImport.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_EditorScenePostImport:
  6. EditorScenePostImport
  7. =====================
  8. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  9. Post-processes scenes after import.
  10. Description
  11. -----------
  12. Imported scenes can be automatically modified right after import by setting their **Custom Script** Import property to a ``tool`` script that inherits from this class.
  13. The :ref:`_post_import<class_EditorScenePostImport_method__post_import>` callback receives the imported scene's root node and returns the modified version of the scene. Usage example:
  14. .. tabs::
  15. .. code-tab:: gdscript
  16. tool # Needed so it runs in editor.
  17. extends EditorScenePostImport
  18. # This sample changes all node names.
  19. # Called right after the scene is imported and gets the root node.
  20. func _post_import(scene):
  21. # Change all node names to "modified_[oldnodename]"
  22. iterate(scene)
  23. return scene # Remember to return the imported scene
  24. func iterate(node):
  25. if node != null:
  26. node.name = "modified_" + node.name
  27. for child in node.get_children():
  28. iterate(child)
  29. .. code-tab:: csharp
  30. using Godot;
  31. // This sample changes all node names.
  32. // Called right after the scene is imported and gets the root node.
  33. [Tool]
  34. public class NodeRenamer : EditorScenePostImport
  35. {
  36. public override Object PostImport(Object scene)
  37. {
  38. // Change all node names to "modified_[oldnodename]"
  39. Iterate(scene as Node);
  40. return scene; // Remember to return the imported scene
  41. }
  42. public void Iterate(Node node)
  43. {
  44. if (node != null)
  45. {
  46. node.Name = "modified_" + node.Name;
  47. foreach (Node child in node.GetChildren())
  48. {
  49. Iterate(child);
  50. }
  51. }
  52. }
  53. }
  54. Tutorials
  55. ---------
  56. - `Importing 3D scenes: Custom script <../tutorials/assets_pipeline/importing_scenes.html#custom-script>`__
  57. Methods
  58. -------
  59. +-----------------------------+--------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`Object<class_Object>` | :ref:`_post_import<class_EditorScenePostImport_method__post_import>` **(** :ref:`Node<class_Node>` scene **)** |virtual| |
  61. +-----------------------------+--------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`String<class_String>` | :ref:`get_source_file<class_EditorScenePostImport_method_get_source_file>` **(** **)** |const| |
  63. +-----------------------------+--------------------------------------------------------------------------------------------------------------------------+
  64. Method Descriptions
  65. -------------------
  66. .. _class_EditorScenePostImport_method__post_import:
  67. - :ref:`Object<class_Object>` **_post_import** **(** :ref:`Node<class_Node>` scene **)** |virtual|
  68. Called after the scene was imported. This method must return the modified version of the scene.
  69. ----
  70. .. _class_EditorScenePostImport_method_get_source_file:
  71. - :ref:`String<class_String>` **get_source_file** **(** **)** |const|
  72. Returns the source file path which got imported (e.g. ``res://scene.dae``).
  73. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  74. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  75. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  76. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  77. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  78. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`