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 🔗
Returns a path, converting path_or_uid if necessary. Fails and returns an empty string if an invalid UID is provided.
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 无效则打印错误。