class_editorscenepostimport.rst 4.3 KB

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