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

ISynchronousAssetProvider

interface 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

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

Public Methods

Method Description
TryLoadAsset Tries to resolve the asset for a key without loading asynchronously.