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

IAssetProvider

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

The base capability shared by asset providers in the localization system.

A provider decides how an address resolves to an asset, for example from built content, a Resources folder, or Addressables. It opts into loading by implementing IAsyncAssetProvider, ISynchronousAssetProvider, or both; the localization system prefers the asynchronous version and falls back to the synchronous one, and on the synchronous paths it uses only synchronous providers. Add an implementation to an AssetProvider chain to make it available. The built-in implementations are ReferencedAssetProvider (synchronous) and ResourceFolderProvider (both).

Additional resources: IAsyncAssetProvider, ISynchronousAssetProvider, AssetProvider, AssetKey

<para>A synchronous provider that resolves assets it already holds in memory.</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) { } } }

Properties

Property Description
Id The identifier a table collection uses to name the provider that serves it.

Public Methods

Method Description
Release Releases an asset previously returned by this provider.