Skip to content
0.2.0-dev Download ZIP
51 lines ·2.3 KB Raw
1<?xml version="1.0" encoding="UTF-8" ?>
2<class name="EditorResourceConversionPlugin" inherits="RefCounted" api_type="editor" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3 <brief_description>
4 Plugin for adding custom converters from one resource format to another in the editor resource picker context menu; for example, converting a [StandardMaterial3D] to a [ShaderMaterial].
5 </brief_description>
6 <description>
7 [EditorResourceConversionPlugin] is invoked when the context menu is brought up for a resource in the editor inspector. Relevant conversion plugins will appear as menu options to convert the given resource to a target type.
8 Below shows an example of a basic plugin that will convert an [ImageTexture] to a [PortableCompressedTexture2D].
9 [codeblocks]
10 [gdscript]
11 extends EditorResourceConversionPlugin
12
13 func _handles(resource: Resource):
14 return resource is ImageTexture
15
16 func _converts_to():
17 return "PortableCompressedTexture2D"
18
19 func _convert(itex: Resource):
20 var ptex = PortableCompressedTexture2D.new()
21 ptex.create_from_image(itex.get_image(), PortableCompressedTexture2D.COMPRESSION_MODE_LOSSLESS)
22 return ptex
23 [/gdscript]
24 [/codeblocks]
25 To use an [EditorResourceConversionPlugin], register it using the [method EditorPlugin.add_resource_conversion_plugin] method first.
26 </description>
27 <tutorials>
28 </tutorials>
29 <methods>
30 <method name="_convert" qualifiers="virtual const">
31 <return type="Resource" />
32 <param index="0" name="resource" type="Resource" />
33 <description>
34 Takes an input [Resource] and converts it to the type given in [method _converts_to]. The returned [Resource] is the result of the conversion, and the input [Resource] remains unchanged.
35 </description>
36 </method>
37 <method name="_converts_to" qualifiers="virtual const">
38 <return type="String" />
39 <description>
40 Returns the class name of the target type of [Resource] that this plugin converts source resources to.
41 </description>
42 </method>
43 <method name="_handles" qualifiers="virtual const">
44 <return type="bool" />
45 <param index="0" name="resource" type="Resource" />
46 <description>
47 Called to determine whether a particular [Resource] can be converted to the target resource type by this plugin.
48 </description>
49 </method>
50 </methods>
51</class>