An optional capability for an asset provider that can resolve an asset immediately, without an asynchronous load.
Implement this alongside IAssetProvider when a provider already has the asset in hand, such as a
direct reference or a synchronous Resources load, so the localization system can resolve it on the
synchronous paths (the GetTable/GetLocalizedString/GetLocalizedAsset accessors, and
references resolved under the LoadingPreference.Synchronous loading preference). A provider that can only load
asynchronously does not implement this interface; the synchronous paths skip it and fall back to whatever is
already cached. A Unity Awaitable cannot be forced to complete on the main thread, so
this interface is how a provider opts in to synchronous resolution rather than blocking one.
Additional resources: IAssetProvider, ResourceDatabase
<para>A provider that keeps assets in memory and resolves them synchronously.</para>
using System.Collections.Generic; using Unity.Localization.Providers; using Object = UnityEngine.Object;
namespace Unity.Localization.Samples { public class SyncAssetProviderExample : IAssetProvider, ISynchronousAssetProvider { readonly Dictionary<string, Object> m_Assets = new();
public void Register(string address, Object asset) => m_Assets[address] = asset;
public bool TryLoadAsset<T>(AssetKey key, out T asset) where T : Object { asset = m_Assets.TryGetValue(key.Address, out var value) ? value as T : null; return asset != null; }
public void Release(Object asset) { } } }
| Method | Description |
|---|---|
| TryLoadAsset | Tries to resolve the asset for a key without loading asynchronously. |