TriLib
Search Results for

    Show / Hide Table of Contents

    Class AssetDownloader

    Provides functionality for downloading 3D model data from a specified URI and loading it into Unity. This class supports various HTTP methods (GET, POST, PUT, DELETE, HEAD) and offers optional asynchronous behavior. The downloaded model can be placed within a specified UnityEngine.GameObject hierarchy, and can handle .zip archives if requested.

    Inheritance
    object
    AssetDownloader
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: TriLibCore
    Assembly: Assembly-CSharp.dll
    Syntax
    public class AssetDownloader

    Methods

    CreateWebRequest(string, HttpRequestMethod, string, int)

    Creates a new UnityEngine.Networking.UnityWebRequest based on the specified parameters, allowing you to configure the request method, data, and timeout. The returned request can be used to download or upload data via HTTP.

    Declaration
    public static UnityWebRequest CreateWebRequest(string uri, AssetDownloader.HttpRequestMethod httpRequestMethod = HttpRequestMethod.Get, string data = null, int timeout = 2000)
    Parameters
    Type Name Description
    string uri

    The URI (URL) to which the request is sent.

    AssetDownloader.HttpRequestMethod httpRequestMethod

    The HTTP method to use (e.g., Get, Post, etc.). Defaults to Get.

    string data

    Optional data or parameters to include in the request. For example, in a GET request, this data will be appended as query parameters.

    int timeout

    The request timeout in seconds. Defaults to 2000 seconds.

    Returns
    Type Description
    UnityWebRequest

    A configured UnityEngine.Networking.UnityWebRequest instance with the specified method, data, and timeout settings.

    LoadModelFromUri(UnityWebRequest, Action<AssetLoaderContext>, Action<AssetLoaderContext>, Action<AssetLoaderContext, float>, Action<IContextualizedError>, GameObject, AssetLoaderOptions, object, string, bool?, bool)

    Initiates an asynchronous download of 3D model data from the specified UnityEngine.Networking.UnityWebRequest, then loads the model (optionally including .zip extraction). The method returns a UnityEngine.Coroutine which you can yield on or allow to run in the background. Once the model is downloaded, TriLib’s AssetLoader will process the data and create corresponding UnityEngine.GameObjects, materials, and other resources.

    Declaration
    public static Coroutine LoadModelFromUri(UnityWebRequest unityWebRequest, Action<AssetLoaderContext> onLoad, Action<AssetLoaderContext> onMaterialsLoad, Action<AssetLoaderContext, float> onProgress, Action<IContextualizedError> onError = null, GameObject wrapperGameObject = null, AssetLoaderOptions assetLoaderOptions = null, object customContextData = null, string fileExtension = null, bool? isZipFile = null, bool haltTask = false)
    Parameters
    Type Name Description
    UnityWebRequest unityWebRequest

    The configured UnityEngine.Networking.UnityWebRequest to download the model. You can create this request using CreateWebRequest(string, HttpRequestMethod, string, int) or provide a custom request.

    Action<AssetLoaderContext> onLoad

    A callback invoked on the main Unity thread once the model data has been read, but before materials are fully loaded. This is useful for performing actions immediately after the base model structure is available.

    Action<AssetLoaderContext> onMaterialsLoad

    A callback invoked on the main Unity thread once all resources (textures, shaders, etc.) have been loaded. This indicates the final stage of model loading.

    Action<AssetLoaderContext, float> onProgress

    A callback invoked whenever the loading progress updates, with a float parameter indicating progress (0 to 1).

    Action<IContextualizedError> onError

    A callback invoked on the main Unity thread if any error occurs during the download or loading process.

    GameObject wrapperGameObject

    An optional parent UnityEngine.GameObject under which the loaded model's UnityEngine.GameObject will be placed. If null, the model is created at the root level.

    AssetLoaderOptions assetLoaderOptions

    The AssetLoaderOptions controlling how the model is processed, including material, animation, and texture loading behaviors.

    object customContextData

    Optional custom data passed to the AssetLoaderContext for use in the loading pipeline.

    string fileExtension

    If known, specify the model file extension (e.g., ".fbx"). If the file is within a .zip, this should be the extension of the internal file.

    bool? isZipFile

    Pass true if the file is a .zip, allowing TriLib to extract and process the contained model. If null, TriLib will try to guess based on the fileExtension.

    bool haltTask

    If true, the loading tasks are created but not started immediately. Use this to chain multiple tasks or delay the loading process.

    Returns
    Type Description
    Coroutine

    A UnityEngine.Coroutine reference that represents the ongoing download and model loading process. You can yield on it in a Unity coroutine or let it run asynchronously.

    Extension Methods

    IObjectExtensions.TryToDispose<T>(object)
    In this article
    Back to top Generated by DocFX