EditorImportPlugin¶
Inherits: ResourceImporter < Reference < Object
类别: 核心
简要说明¶
在编辑器中注册自定义资源导入程序。使用该类分析任何文件并将其作为新资源类型导入。
方法¶
get_import_options ( int preset ) virtual |
|
get_import_order ( ) virtual |
|
get_importer_name ( ) virtual |
|
get_option_visibility ( String option, Dictionary options ) virtual |
|
get_preset_count ( ) virtual |
|
get_preset_name ( int preset ) virtual |
|
get_priority ( ) virtual |
|
get_recognized_extensions ( ) virtual |
|
get_resource_type ( ) virtual |
|
get_save_extension ( ) virtual |
|
get_visible_name ( ) virtual |
|
import ( String source_file, String save_path, Dictionary options, Array platform_variants, Array gen_files ) virtual |
描述¶
editorimportplugins提供了一种扩展编辑器资源导入功能的方法。使用它们从自定义文件中导入资源或提供编辑器现有导入器的替代项。注册您的 EditorPlugin 具有 EditorPlugin.add_import_plugin .
editorimportplugins通过与特定的文件扩展名和资源类型关联来工作。见 get_recognized_extensions 和 get_resource_type . 它们可以选择指定一些影响导入过程的导入预设。editorimportplugins负责创建资源并将其保存在 .import
目录。
下面是一个导入 Mesh 来自扩展名为“.special”或“.spec”的文件:
tool
extends EditorImportPlugin
func get_importer_name():
return "my.special.plugin"
func get_visible_name():
return "Special Mesh Importer"
func get_recognized_extensions():
return ["special", "spec"]
func get_save_extension():
return "mesh"
func get_resource_type():
return "Mesh"
func get_preset_count():
return 1
func get_preset_name(i):
return "Default"
func get_import_options(i):
return [{"name": "my_option", "default_value": false}]
func import(source_file, save_path, options, platform_variants, gen_files):
var file = File.new()
if file.open(source_file, File.READ) != OK:
return FAILED
var mesh = Mesh.new()
# Fill the Mesh with data read in "file", left as an exercise to the reader
var filename = save_path + "." + get_save_extension()
ResourceSaver.save(filename, mesh)
return OK
方法说明¶
获取此索引处预设的选项和默认值。返回具有以下键的字典数组: name
, default_value
, property_hint
(可选) hint_string
(可选) usage
(可选)。
int get_import_order ( ) virtual
获取导入资源时要运行的导入程序的顺序。稍后将调用更高的值。使用此选项可确保导入程序在已导入依赖项之后运行。
String get_importer_name ( ) virtual
获取导入程序的唯一名称。
bool get_option_visibility ( String option, Dictionary options ) virtual
int get_preset_count ( ) virtual
获取插件定义的初始预设数。使用 get_import_options 获取预设和 get_preset_name 获取预设的名称。
获取此索引处预设的选项的名称。
float get_priority ( ) virtual
获取此插件对于已识别扩展的优先级。优先级别更高的插件将是首选。默认优先级为 1.0
.
Array get_recognized_extensions ( ) virtual
获取要与此加载程序关联的文件扩展名列表(不区分大小写)。例如 ["obj"]
.
String get_resource_type ( ) virtual
获取与此加载程序关联的godot资源类型。例如 "Mesh"
或 "Animation"
.
String get_save_extension ( ) virtual
获取用于将此资源保存到 .import
目录。
String get_visible_name ( ) virtual
获取要在导入窗口中显示的名称。