docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method LoadAssetAsync

    LoadAssetAsync()

    Provides a localized asset from a AssetTable with the TableReference and the the asset that matches TableEntryReference.

    Declaration
    public AsyncOperationHandle<TObject> LoadAssetAsync()
    Returns
    Type Description
    AsyncOperationHandle<TObject>

    Returns the loading operation for the request.

    Remarks

    The asset may have already been loaded, either during a previous operation or if Preload mode is used. Check the UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle.IsDone property to see if the asset is already loaded and therefore is immediately available. See Async operation handling for further details.

    Examples

    This example shows how LoadAssetAsync() can be used to request a sprite asset when the SelectedLocale changes.

    public class LocalizedSpriteExample : MonoBehaviour
    {
        public LocalizedSprite localizedSprite;
    
        public Image image;
    
        void OnEnable()
        {
            LocalizationSettings.SelectedLocaleChanged += SelectedLocaleChanged;
            StartCoroutine(LoadAssetCoroutine());
        }
    
        void OnDisable()
        {
            LocalizationSettings.SelectedLocaleChanged -= SelectedLocaleChanged;
        }
    
        void SelectedLocaleChanged(Locale obj)
        {
            StartCoroutine(LoadAssetCoroutine());
        }
    
        IEnumerator LoadAssetCoroutine()
        {
            var operation = localizedSprite.LoadAssetAsync();
            yield return operation;
            image.sprite = operation.Result;
        }
    }

    LoadAssetAsync<T>()

    Overrides the asset's default type. This loads a type from AssetTable with the TableReference and the the asset that matchesTableEntryReference. This helps to filter sub-assets when trying to load them and they share a common type among other sub-assets with the same name.
    For example, an asset could have the following structure:
    Main Asset [GameObject]
    - Sub Asset[GameObject]
    - Sub Asset[Mesh] If you were using a LocalizedObject, callingLoadAsset orLoadAssetAsObjectAsync() to load "Main Asset/Sub Asset" would return the first matching asset. In this case, this would be the GameObject version. With this method, you could provide the type Mesh to filter out the GameObject version and return the Mesh.

    Declaration
    public override AsyncOperationHandle<T> LoadAssetAsync<T>() where T : Object
    Returns
    Type Description
    AsyncOperationHandle<T>

    Returns the loading operation for the request.

    Type Parameters
    Name Description
    T
    Overrides
    LocalizedAssetBase.LoadAssetAsync<TObject>()
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)