AssetKey
Identifies a single asset to load through an asset provider. The key pairs a provider specific address with an expected asset type, and optionally the name of a sub-asset at that address.
Read time 2 minutesLast updated 14 days ago
Definition
- Type: Struct
- Namespace: Unity.Localization.Providers
- Assembly: UnityEngine.LocalizationRuntimeModule
- Implements: IEquatable<AssetKey>
public readonly struct AssetKey : IEquatable<AssetKey>
Remarks
The AssetKey.Address is opaque to the cache and is interpreted by the active provider: ReferencedAssetProvider treats it as the key into its address-to-reference map, ResourceFolderProvider treats it as a path, and a provider installed from a package (for example an Addressables-backed one) can interpret it as its own address. AssetKey.Type is part of the identity because one address can hold objects of several types, so two keys with the same address but a different type are distinct.
ResourcesAdditional Resources: IAssetProvider, AssetProvider, ReferencedAssetProvider, ResourceFolderProvider
Create a key for a texture and inspect its parts.
Examples
using Unity.Localization.Providers;using UnityEngine;namespace Unity.Localization.Samples{ public class AssetKeyOverviewExample { public void Run() { var key = new AssetKey("UI/Flags/Fr", typeof(Texture2D)); Debug.Log(key.Address); // UI/Flags/Fr Debug.Log(key.Type.Name); // Texture2D Debug.Log(key.IsValid); // True } }}
Constructors
Constructor | Description |
|---|---|
| AssetKey(System.String,System.Type,System.String) | Creates a key for the given address, interpreted by the active provider. |
Properties
Property | Description |
|---|---|
| Address | The provider-specific address that identifies the asset. |
| IsValid | Whether this key carries an address. |
| SubAssetName | The name of the sub-asset at the address, or null when the key targets the whole asset. |
| Type | The expected asset type. |
Methods
Method | Description |
|---|---|
| Equals | Checks whether this key equals another object. |
| GetHashCode | Computes a hash code for this key. |
| ToString | Returns a readable string describing this key. |
Operators
Operator | Description |
|---|---|
| operator == | Compares two keys for equality. |
| operator != | Compares two keys for inequality. |