AssetReference
- Namespace: Turian.Engine.Core
- Source File: AssetReference.cs
Represents a serializable reference to an asset stored in the asset database.
Properties
AssetId
(Guid) { get; set }: Gets or sets the unique identifier of the referenced asset.
IsEmpty
(bool): Gets a value indicating whether this reference does not point to any asset.
AssetIdOrNull
(Guid?): Gets the referenced asset identifier or when the reference is empty.
Public Methods
Clear
public void Clear()
Clears the current reference.
Set
public void Set(Guid assetId)
Updates this reference to point to the specified asset identifier.
Parameters:
assetId(Guid): The asset identifier to reference.
Set
public void Set(TAsset asset)
Updates this reference to point to the specified asset.
Parameters:
asset(TAsset): The asset to reference.
Resolve
public TAsset? Resolve(AssetDatabase assetDatabase)
Resolves the referenced asset metadata from the given asset database.
Parameters:
assetDatabase(AssetDatabase): The asset database used to resolve the reference.
Returns: TAsset?
- The referenced asset metadata instance when found and of the expected type; otherwise, .
TryResolve
public bool TryResolve(AssetDatabase assetDatabase, TAsset? asset)
Tries to resolve the referenced asset metadata from the given asset database.
Parameters:
assetDatabase(AssetDatabase): The asset database used to resolve the reference.asset(TAsset?): When this method returns, contains the resolved asset if found; otherwise, null.
Returns: bool
- if the asset could be resolved; otherwise, .
LoadAsync
public Task<TAsset?> LoadAsync(IAssetLoader loader)
Loads the referenced asset content through the provided loader, returning the shared cached instance when available. Returns when the reference is empty, the asset cannot be resolved, or the cached type does not match .
Parameters:
loader(IAssetLoader): The asset loader used to fetch or resolve the cached instance.
Returns: Task<TAsset?>
GetLoaded
public TAsset? GetLoaded(IAssetLoader loader)
Returns the cached asset instance if the loader has already resolved this reference; otherwise, .
Parameters:
loader(IAssetLoader): The asset loader used to consult the cache.
Returns: TAsset?
ToString
public override string ToString()
Returns a string representation of this asset reference.
Returns: string
- A display-friendly string representation.
Equals
public override bool Equals(object? obj)
Parameters:
obj(object?)
Returns: bool
Equals
public bool Equals(AssetReference<TAsset>? other)
Determines whether this reference and another reference point to the same asset.
Parameters:
other(AssetReference? ): The other reference to compare with.
Returns: bool
- when both references point to the same asset; otherwise, .
GetHashCode
public override int GetHashCode()
Returns: int
From
public static AssetReference<TAsset> From(TAsset asset)
Creates an asset reference pointing to the specified asset.
Parameters:
asset(TAsset): The asset to reference.
Returns: AssetReference<TAsset>
- A new asset reference.
From
public static AssetReference<TAsset> From(Guid assetId)
Creates an asset reference pointing to the specified asset identifier.
Parameters:
assetId(Guid): The asset identifier to reference.
Returns: AssetReference<TAsset>
- A new asset reference.