ResourceUID
繼承: Object
管理專案中所有資源的唯一識別碼的單例。
說明
Resource UIDs (Unique IDentifiers) allow the engine to keep references between resources intact, even if files are renamed or moved. They can be accessed with uid://.
ResourceUID keeps track of all registered resource UIDs in a project, generates new UIDs, and converts between their string and integer representations.
方法
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) 🔗
Like create_id(), but the UID is seeded with the provided path and project name. UIDs generated for that path will be always the same within the current project.
String ensure_path(path_or_uid: String) static 🔗
Returns a path, converting path_or_uid if necessary. Prints an error if provided an invalid 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 🔗
Converts the provided resource path to a UID. Returns the unchanged path if it has no associated 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 🔗
Converts the provided uid to a path. Prints an error if the UID is invalid.