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...
ResourceUID
繼承: Object
管理專案中所有資源的唯一識別碼的單例。
說明
資源 UID(Unique IDentifier,唯一標識符)可以使引擎保持資源之間參照關係的完整性,即使檔案發生重新命名或移動。可以使用 uid:// 存取。
ResourceUID 能夠追蹤專案中所有已注冊的資源 UID,生成新的 UID,也能夠將標識符在字串表示和整數表示之間進行轉換。
方法
void |
|
create_id_for_path(path: String) |
|
ensure_path(path_or_uid: String) static |
|
get_id_path(id: int) const |
|
id_to_text(id: int) const |
|
path_to_uid(path: String) static |
|
void |
|
void |
|
text_to_id(text_id: String) const |
|
uid_to_path(uid: String) static |
常數
INVALID_ID = -1 🔗
用於無效 UID 的值,例如無法載入的資源。
對應的文字表示為 uid://<invalid>。
方法說明
void add_id(id: int, path: String) 🔗
新增一個新的 UID 值,將其對應到給定的資源路徑。
如果 UID 已經存在,則會返回錯誤,因此請務必先使用 has_id() 進行檢查,或者改用 set_id()。
生成隨機的資源 UID,該 UID 在目前載入的 UID 列表中保證唯一。
要註冊這個 UID,你必須呼叫 add_id() 或 set_id()。
int create_id_for_path(path: String) 🔗
與 create_id() 型別,但是 UID 會使用 path 路徑和專案名稱設定隨機數種子。在目前專案中為該路徑生成的 UID 始終相同。
String ensure_path(path_or_uid: String) static 🔗
返迴路徑,必要時轉換 path_or_uid。如果提供了無效的 UID,則操作失敗並回傳空字串。
String get_id_path(id: int) const 🔗
返回給定 UID 值引用的路徑。
如果 UID 不存在則失敗並報告有錯,因此請務必使用 has_id() 事先檢查。
返回給定的 UID 值是否為快取所知。
String id_to_text(id: int) const 🔗
將給定的 UID 轉換為 uid:// 字串值。
String path_to_uid(path: String) static 🔗
將 path 中提供的資來源路徑轉換為 UID。如果沒有與之關聯的 UID 則會原樣回傳該路徑。
從快取中刪除一個已載入的 UID 值。
如果 UID 不存在則失敗並報告有錯,因此請務必提前使用 has_id() 檢查。
void set_id(id: int, path: String) 🔗
更新現有 UID 的資源路徑。
如果 UID 不存在,則失敗並出現錯誤,因此請務必提前使用 has_id() 檢查,或者改用 add_id()。
int text_to_id(text_id: String) const 🔗
從給定的 uid:// 字串中提取 UID 值。
String uid_to_path(uid: String) static 🔗
將 uid 轉換為路徑。如果該 UID 無效則輸出錯誤。