Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

AssetKey

struct in Unity.Localization.Providers

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

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.

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 Resources 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.

Additional resources: IAssetProvider, AssetProvider, ReferencedAssetProvider, ResourceFolderProvider

<para>Create a key for a texture and inspect its parts.</para>

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 } } }

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.

Constructors

Constructor Description
AssetKey Creates a key for the given address, interpreted by the active provider.

Public Methods

Method Description
Equals Checks whether this key identifies the same asset as another.
GetHashCode Computes a hash code for this key.
ToString Returns a readable string describing this key.

Operators

Operator Description
operator != Compares two keys for inequality.
operator == Compares two keys for equality.