LoadAssetAsync<T>(AssetKey, CancellationToken)
Loads the asset for the key from a Resources folder as the requested type.
Read time 1 minuteLast updated 13 days ago
Definition
- Type: Method
- Namespace: Unity.Localization.Providers
- Assembly: UnityEngine.LocalizationRuntimeModule
public Awaitable<T> LoadAssetAsync<T>(AssetKey key, CancellationToken cancellationToken) where T : Object
Parameters
Returns
Type | Description |
|---|---|
| Awaitable<T> | The loaded asset, or |
Remarks
Resolves the address through any registered alias, then loads it from as , or as AssetKey.Type when is the base Object. When AssetKey.SubAssetName is set, the named sub-asset at the path is returned. Completes with when nothing at the path matches, and throws OperationCanceledException when the load is cancelled.
ResourcesTTnullLoad a sprite from a Resources folder.
Examples
using System.Threading;using Unity.Localization.Providers;using UnityEngine;namespace Unity.Localization.Samples{ public class ResourceFolderProviderLoadAssetGenericExample { public async Awaitable Run() { var provider = new ResourceFolderProvider(); var icon = await provider.LoadAssetAsync<Sprite>( new AssetKey("UI/Icons/Settings", typeof(Sprite)), CancellationToken.None); if (icon != null) Debug.Log(icon.name); } }}