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(path: String, metadata: Dictionary, base: Control) virtual const |
|
void |
request_thumbnail(path: String, control: TextureRect) const |
方法說明
bool _handles(type: String) virtual const 🔗
如果外掛程式要處理給定的 Resource 型別 type,則返回 true。
Control _make_tooltip_for_path(path: String, metadata: Dictionary, base: Control) 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(path: String, control: TextureRect) const 🔗
為給定的 TextureRect 請求縮略圖。縮略圖使用 EditorResourcePreview 非同步創建,會在可用時自動設定。