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

ResourceFolderProvider.LoadAssetAsync

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

Declaration

public Awaitable<T> LoadAssetAsync(AssetKey key, CancellationToken cancellationToken);

Parameters

Parameter Description
key The asset to load.
cancellationToken A token that cancels the load.

Returns

Awaitable<T> The loaded asset, or null when nothing at the path matches.

Description

Loads the asset for the key from a Resources folder as the requested type.

Resolves the address through any registered alias, then loads it from Resources as T, or as AssetKey.Type when T is the base Object. When AssetKey.SubAssetName is set, the named sub-asset at the path is returned. Completes with null when nothing at the path matches, and throws OperationCanceledException when the load is cancelled.

<para>Load a sprite from a Resources folder.</para>

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