EditorImportPlugin
Registers a custom resource importer in the editor. Use the class to parse any file and import it as a new resource type.
EditorImportPlugin.swift:24class EditorImportPlugin
EditorImportPlugin
s provide a way to extend the editor’s resource import functionality. Use them to import resources from custom files or to provide alternatives to the editor’s existing importers.
EditorImportPlugins work by associating with specific file extensions and a resource type. See _getRecognizedExtensions
and _getResourceType
. They may optionally specify some import presets that affect the import process. EditorImportPlugins are responsible for creating the resources and saving them in the .godot/imported
directory (see ProjectSettings/application/config/useHiddenProjectDataDirectory
).
Below is an example EditorImportPlugin that imports a Mesh
from a file with the extension “.special” or “.spec”:
To use EditorImportPlugin
, register it using the addImportPlugin(importer:firstPriority:)
method first.
Superclasses
class ResourceImporter
Base class for resource importers.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Type members
Instance members
func appendImportExternalResource(path: String, customOptions: GDictionary, customImporter: String, generatorParameters: Variant
) -> GodotError This function can only be called during the
_import(sourceFile:savePath:options:platformVariants:genFiles:)
callback and it allows manually importing resources from it. This is useful when the imported file generates external resources that require importing (as example, images). Custom parameters for the “.import” file can be passed via thecustomOptions
. Additionally, in cases where multiple importers can handle a file, thecustomImporter
ca be specified to force a specific one. This function performs a resource import and returns immediately with a success or error code.generatorParameters
defines optional extra metadata which will be stored as [code skip-lint]generator_parametersin the
remapsection of the
.import` file, for example to store a md5 hash of the source data.
Show implementation details (13)
Hide implementation details
func _canImportThreaded(
) -> Bool Tells whether this importer can be run in parallel on threads, or, on the contrary, it’s only safe for the editor to call it from the main thread, for one file at a time.
func _getImportOptions(path: String, presetIndex: Int32
) -> VariantCollection<GDictionary> Gets the options and default values for the preset at this index. Returns an Array of Dictionaries with the following keys:
name
,default_value
,property_hint
(optional),hint_string
(optional),usage
(optional).func _getImportOrder(
) -> Int32 Gets the order of this importer to be run when importing resources. Importers with lower import orders will be called first, and higher values will be called later. Use this to ensure the importer runs after the dependencies are already imported. The default import order is
0
unless overridden by a specific importer. SeeResourceImporter.ImportOrder
for some predefined values.func _getImporterName(
) -> String Gets the unique name of the importer.
func _getOptionVisibility(path: String, optionName: StringName, options: GDictionary
) -> Bool This method can be overridden to hide specific import options if conditions are met. This is mainly useful for hiding options that depend on others if one of them is disabled. For example:
func _getPresetCount(
) -> Int32 Gets the number of initial presets defined by the plugin. Use
_getImportOptions(path:presetIndex:)
to get the default options for the preset and_getPresetName(presetIndex:)
to get the name of the preset.func _getPresetName(presetIndex: Int32
) -> String Gets the name of the options preset at this index.
func _getPriority(
) -> Double Gets the priority of this plugin for the recognized extension. Higher priority plugins will be preferred. The default priority is
1.0
.func _getRecognizedExtensions(
) -> PackedStringArray Gets the list of file extensions to associate with this loader (case-insensitive). e.g.
["obj"]
.func _getResourceType(
) -> String Gets the Godot resource type associated with this loader. e.g.
"Mesh"
or"Animation"
.func _getSaveExtension(
) -> String Gets the extension used to save this resource in the
.godot/imported
directory (seeProjectSettings/application/config/useHiddenProjectDataDirectory
).func _getVisibleName(
) -> String Gets the name to display in the import window. You should choose this name as a continuation to “Import as”, e.g. “Import as Special Mesh”.
func _import(sourceFile: String, savePath: String, options: GDictionary, platformVariants: VariantCollection<String>, genFiles: VariantCollection<String>
) -> GodotError Imports
sourceFile
intosavePath
with the importoptions
specified. TheplatformVariants
andgenFiles
arrays will be modified by this function.