ISynchronousAssetProvider
An optional capability for an asset provider that can resolve an asset immediately, without an asynchronous load.
Read time 1 minuteLast updated 13 days ago
Definition
- Type: Interface
- Namespace: Unity.Localization.Providers
- Assembly: UnityEngine.LocalizationRuntimeModule
public interface ISynchronousAssetProvider
Remarks
Implement this alongside IAssetProvider when a provider already has the asset in hand, such as a direct reference or a synchronous load, so the localization system can resolve it on the synchronous paths (the // 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.
ResourcesGetTableGetLocalizedStringGetLocalizedAssetAdditional Resources: IAssetProvider, ResourceDatabase
A provider that keeps assets in memory and resolves them synchronously.
Examples
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) { } }}
Methods
Method | Description |
|---|---|
| TryLoadAsset | Tries to resolve the asset for a key without loading asynchronously. |