Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
EditorResourceTooltipPlugin¶
继承: RefCounted < Object
为处理的资源类型制作高阶工具提示的插件。
描述¶
FileSystemDock 使用的资源工具提示插件,能够为指定资源生成自定义工具提示。例如,Texture2D 的工具提示会显示较大的预览和该纹理的尺寸。
插件必须先使用 FileSystemDock.add_resource_tooltip_plugin 注册。用户悬停在文件系统面板中该插件能够处理的资源上时,就会调用 _make_tooltip_for_path 来创建工具提示。工作原理类似于 Control._make_custom_tooltip。
方法¶
_make_tooltip_for_path ( String path, Dictionary metadata, Control base ) virtual const |
|
void |
request_thumbnail ( String path, TextureRect control ) const |
方法说明¶
bool _handles ( String type ) virtual const
如果插件要处理给定的 Resource 类型 type
,则返回 true
。
Control _make_tooltip_for_path ( String path, Dictionary metadata, Control base ) virtual const
创建并返回工具提示,会在用户悬停在文件系统面板上路径为 path
的资源上时显示。
元数据字典 metadata
由预览生成器提供(见 EditorResourcePreviewGenerator._generate)。
base
是基础的默认工具提示,是一个包含文件名、类型、大小标签的 VBoxContainer。如果其他插件也能够处理相同的文件类型,那么 base
就是上一个插件的输出。为了达到最佳效果,请确保基础工具提示是返回的 Control 的一部分。
注意:不建议使用 ResourceLoader.load,尤其是模型、纹理等开销较大的资源,否则会在创建工具提示时让编辑器失去响应。如果想要在工具提示中显示预览,可以使用 request_thumbnail。
注意:如果你决定要丢弃 base
,请确保调用了 Node.queue_free,否则不会自动释放。
func _make_tooltip_for_path(path, metadata, base):
var t_rect = TextureRect.new()
request_thumbnail(path, t_rect)
base.add_child(t_rect) # TextureRect 会出现在工具提示的底部。
return base
void request_thumbnail ( String path, TextureRect control ) const
为给定的 TextureRect 请求缩略图。缩略图使用 EditorResourcePreview 异步创建,会在可用时自动设置。