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

ReferencedAssetProvider

class in Unity.Localization.Providers


Implements interfaces:IAssetProvider, ISynchronousAssetProvider

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 asset provider that resolves an address to a directly referenced asset. Use it when assets are assigned by reference rather than loaded from built content, a Resources folder, or Addressables.

The address-to-reference map is populated through ReferencedAssetProvider.Add, so AssetKey.Address is the key into that map. Loads complete immediately because the assets are already in memory. ReferencedAssetProvider.Release is a no-op: the references are owned by whatever holds this provider, so there is nothing to unload. The map is authored programmatically by the table editor, so it is hidden from the inspector.

Additional resources: IAssetProvider, AssetProvider, ResourceFolderProvider, AssetKey

<para>Register a texture by address and load it back through the provider.</para>

using Unity.Localization.Providers;
using UnityEngine;

namespace Unity.Localization.Samples { public class ReferencedAssetProviderOverviewExample { public void Run() { var provider = new ReferencedAssetProvider(); provider.Add("UI/Logo", new Texture2D(2, 2));

var resolved = provider.TryLoadAsset<Texture2D>(new AssetKey("UI/Logo", typeof(Texture2D)), out var logo);

Debug.Log(resolved); // True Debug.Log(logo != null); // True } } }

Public Methods

Method Description
Add Maps an address to a directly referenced asset, replacing any existing mapping for that address.
Contains Checks whether an asset is registered under the given address.
Release Does nothing, because this provider does not own the assets it returns.
Remove Removes any entry registered under the given address.
TryLoadAsset Resolves the referenced asset for the key without an asynchronous load.