docs.unity.cn

Addressables 1.19.19

    Show / Hide Table of Contents

    Method InitializeAsync

    InitializeAsync()

    Initialize the Addressables system, if needed.

    Declaration
    public static AsyncOperationHandle<IResourceLocator> InitializeAsync()
    Returns
    Type Description
    AsyncOperationHandle<IResourceLocator>

    The operation handle for the request.

    Remarks

    The Addressables system initializes itself at runtime the first time you call an Addressables API function. You can call this function explicitly to initialize Addressables earlier. This function does nothing if initialization has already occurred.

    The initialization process:

    • Sets up the ResourceManager and ResourceLocators
    • Loads the ResourceManagerRuntimeData object, which is created by the Addressables build
    • Executes IInitializableObject operations
    • Optionally, checks for an updated content catalog (true by default)
    • Loads the content catalog

    The Result object contained in the AsyncOperationHandle<TObject> returned by this function contains a list of Addressable keys and a method that can be used to gather the IResourceLocation instances for a given key and asset type. You must access the Result object in a Completed event handler. To access the handle in a coroutine or Task-based function, pass false to the InitializeAsync(Boolean) overload of this function. Otherwise, the Addressables system releases the AsyncOperationHandle<TObject> object before control returns to your code.

    Initializing Addressables manually can improve performance of your first loading operations since they do not need to wait for initialization to complete. In addition, it can help when debugging early loading operations by separating out the initialization process.

    See also:

    • Customizing initialization
    • Managing catalogs at runtime

    InitializeAsync(Boolean)

    Initialize the Addressables system, if needed.

    Declaration
    public static AsyncOperationHandle<IResourceLocator> InitializeAsync(bool autoReleaseHandle)
    Parameters
    Type Name Description
    Boolean autoReleaseHandle

    If true, the handle is automatically released on completion.

    Returns
    Type Description
    AsyncOperationHandle<IResourceLocator>

    The operation handle for the request.

    Remarks

    The Addressables system initializes itself at runtime the first time you call an Addressables API function. You can call this function explicitly to initialize Addressables earlier. This function does nothing if initialization has already occurred.

    The initialization process:

    • Sets up the ResourceManager and ResourceLocators
    • Loads the ResourceManagerRuntimeData object, which is created by the Addressables build
    • Executes IInitializableObject operations
    • Optionally, checks for an updated content catalog (true by default)
    • Loads the content catalog

    The Result object contained in the AsyncOperationHandle<TObject> returned by this function contains a list of Addressable keys and a method that can be used to gather the IResourceLocation instances for a given key and asset type. To access the Result object, use a Completed event handler or set autoReleaseHandle to false.

    Initializing Addressables manually can improve performance of your first loading operations since they do not need to wait for initialization to complete. In addition, it can help when debugging early loading operations by separating out the initialization process.

    See also:

    • Customizing initialization
    • Managing catalogs at runtime
    In This Article
    • InitializeAsync()
    • InitializeAsync(Boolean)
    Back to top Copyright © 2022 Unity Technologies
    Generated by DocFX
    on Friday, March 4, 2022
    Terms of use