跳转至

GFResourceIdentity

API Reference / Standard / 类索引

  • 路径:addons/gf/standard/utilities/assets/gf_resource_identity.gd
  • 模块:Standard
  • 继承:RefCounted
  • API:public
  • 类别:值对象 (value_object)
  • 首次版本:8.0.0

资源键、路径和 UID 的规范化身份快照。 该对象只描述资源身份,不加载资源、不拥有缓存,也不规定项目目录策略。 它适合用于资源解析、加载状态、诊断报告和后续缓存键迁移的统一数据边界。

成员概览

类型 名称 签名
常量 SCHEME_RES const SCHEME_RES: StringName = &"res"
常量 SCHEME_UID const SCHEME_UID: StringName = &"uid"
常量 SCHEME_USER const SCHEME_USER: StringName = &"user"
常量 SCHEME_NONE const SCHEME_NONE: StringName = &""
属性 resource_key var resource_key: StringName = &""
属性 raw_path var raw_path: String = ""
属性 canonical_path var canonical_path: String = ""
属性 uid_path var uid_path: String = ""
属性 type_hint var type_hint: String = ""
属性 scheme var scheme: StringName = SCHEME_NONE
属性 extension var extension: String = ""
属性 cache_key var cache_key: String = ""
属性 exists var exists: bool = false
属性 metadata var metadata: Dictionary = {}
方法 configure func configure( p_resource_key: StringName, p_path: String, p_type_hint: String = "", options: Dictionary = {} ) -> GFResourceIdentity:
方法 has_identity func has_identity() -> bool:
方法 to_dictionary func to_dictionary() -> Dictionary:
方法 duplicate_identity func duplicate_identity() -> GFResourceIdentity:
方法 from_path static func from_path( path: String, p_resource_key: StringName = &"", p_type_hint: String = "", options: Dictionary = {} ) -> GFResourceIdentity:
方法 from_dictionary static func from_dictionary(data: Dictionary) -> GFResourceIdentity:

常量

SCHEME_RES

  • API:public
  • 首次版本:8.0.0
const SCHEME_RES: StringName = &"res"

普通项目资源路径 scheme。

SCHEME_UID

  • API:public
  • 首次版本:8.0.0
const SCHEME_UID: StringName = &"uid"

Godot UID 资源路径 scheme。

SCHEME_USER

  • API:public
  • 首次版本:8.0.0
const SCHEME_USER: StringName = &"user"

用户数据路径 scheme。

SCHEME_NONE

  • API:public
  • 首次版本:8.0.0
const SCHEME_NONE: StringName = &""

没有可识别 scheme。

属性

resource_key

  • API:public
  • 首次版本:8.0.0
var resource_key: StringName = &""

稳定资源键;可为空。

raw_path

  • API:public
  • 首次版本:8.0.0
var raw_path: String = ""

调用方传入的原始路径文本。

canonical_path

  • API:public
  • 首次版本:8.0.0
var canonical_path: String = ""

规范化路径。uid:// 可解析时会回解为 Godot 当前记录的资源路径。

uid_path

  • API:public
  • 首次版本:8.0.0
var uid_path: String = ""

Godot UID 路径;无法取得 UID 时为空。

type_hint

  • API:public
  • 首次版本:8.0.0
var type_hint: String = ""

ResourceLoader 类型提示;可为空。

scheme

  • API:public
  • 首次版本:8.0.0
var scheme: StringName = SCHEME_NONE

路径 scheme,例如 resuiduser

extension

  • API:public
  • 首次版本:8.0.0
var extension: String = ""

规范化路径扩展名,不含点号。

cache_key

  • API:public
  • 首次版本:8.0.0
var cache_key: String = ""

推荐缓存键。优先使用 UID,其次使用规范化路径,最后使用资源键。

exists

  • API:public
  • 首次版本:8.0.0
var exists: bool = false

当前工程中是否能确认该资源存在。

metadata

  • API:public
  • 首次版本:8.0.0
var metadata: Dictionary = {}

调用方元数据。

结构:

  • metadata: Dictionary with caller-defined identity metadata.

方法

configure

  • API:public
  • 首次版本:8.0.0
func configure( p_resource_key: StringName, p_path: String, p_type_hint: String = "", options: Dictionary = {} ) -> GFResourceIdentity:

配置资源身份。

参数:

名称 说明
p_resource_key 稳定资源键;可为空。
p_path 原始资源路径,支持 res://uid://user://
p_type_hint 可选 ResourceLoader 类型提示。
options 可选项,支持 check_exists 和 metadata。

返回:当前身份对象。

结构:

  • options: Dictionary with optional check_exists: bool and metadata: Dictionary.

has_identity

  • API:public
  • 首次版本:8.0.0
func has_identity() -> bool:

检查身份是否有路径或资源键。

返回:有路径或资源键时返回 true。

to_dictionary

  • API:public
  • 首次版本:8.0.0
func to_dictionary() -> Dictionary:

导出可序列化字典。

返回:资源身份字典。

结构:

  • return: Dictionary with resource_key, raw_path, canonical_path, uid_path, type_hint, scheme, extension, cache_key, exists, and metadata.

duplicate_identity

  • API:public
  • 首次版本:8.0.0
func duplicate_identity() -> GFResourceIdentity:

创建资源身份副本。

返回:身份副本。

from_path

  • API:public
  • 首次版本:8.0.0
static func from_path( path: String, p_resource_key: StringName = &"", p_type_hint: String = "", options: Dictionary = {} ) -> GFResourceIdentity:

由路径创建资源身份。

参数:

名称 说明
path 原始资源路径。
p_resource_key 可选稳定资源键。
p_type_hint 可选 ResourceLoader 类型提示。
options 可选项,支持 check_exists 和 metadata。

返回:新身份对象。

结构:

  • options: Dictionary with optional check_exists: bool and metadata: Dictionary.

from_dictionary

  • API:public
  • 首次版本:8.0.0
static func from_dictionary(data: Dictionary) -> GFResourceIdentity:

从字典恢复资源身份快照。

参数:

名称 说明
data to_dictionary() 兼容字典。

返回:身份对象。

结构:

  • data: Dictionary with resource_key, raw_path, canonical_path, uid_path, type_hint, scheme, extension, cache_key, exists, and metadata.