TriLib
Search Results for

    Show / Hide Table of Contents

    Class AssetLoaderZip

    Provides methods to load 3D models from a .zip file or stream using TriLib. It wraps around the core AssetLoader methods, automatically unpacking the first suitable 3D model file found within the archive and configuring any external data mappers necessary for successful loading of textures, materials, and other resources.

    Typical use involves calling one of the public methods (e.g., LoadModelFromZipFile(string, Action<AssetLoaderContext>, Action<AssetLoaderContext>, Action<AssetLoaderContext, float>, Action<IContextualizedError>, GameObject, AssetLoaderOptions, object, string, bool, Action<AssetLoaderContext>) or LoadModelFromZipStream(Stream, Action<AssetLoaderContext>, Action<AssetLoaderContext>, Action<AssetLoaderContext, float>, Action<IContextualizedError>, GameObject, AssetLoaderOptions, object, string, bool, string, Action<AssetLoaderContext>)) to load a zipped model either synchronously or asynchronously.

    Inheritance
    object
    AssetLoaderZip
    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 static class AssetLoaderZip
    Remarks

    Note that these methods rely on TriLib’s AssetLoader for the final stage of model loading and may incorporate ZipFileTextureMapper and ZipFileExternalDataMapper to handle external textures and data.

    Methods

    LoadModelFromZipFile(string, Action<AssetLoaderContext>, Action<AssetLoaderContext>, Action<AssetLoaderContext, float>, Action<IContextualizedError>, GameObject, AssetLoaderOptions, object, string, bool, Action<AssetLoaderContext>)

    Loads the first recognized model file found within the specified .zip archive asynchronously (on a separate thread if supported) and returns the resulting AssetLoaderContext.

    Declaration
    public static AssetLoaderContext LoadModelFromZipFile(string path, 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 haltTask = false, Action<AssetLoaderContext> onPreLoad = null)
    Parameters
    Type Name Description
    string path

    The file path pointing to the .zip archive.

    Action<AssetLoaderContext> onLoad

    Callback invoked on the main thread once the model is loaded (but materials may still be pending).

    Action<AssetLoaderContext> onMaterialsLoad

    Callback invoked on the main thread after all materials (textures, shaders, etc.) have finished loading.

    Action<AssetLoaderContext, float> onProgress

    Callback invoked when loading progress changes. Accepts an AssetLoaderContext and a float in the range [0, 1].

    Action<IContextualizedError> onError

    Callback invoked on the main thread if any error occurs during .zip extraction or model loading.

    GameObject wrapperGameObject

    Optional parent UnityEngine.GameObject for the resulting model hierarchy. If null, the model loads at the root scene level.

    AssetLoaderOptions assetLoaderOptions

    The AssetLoaderOptions controlling how the model is loaded (e.g., material/texture mappers, animation settings).

    object customContextData

    User-defined data to store in the AssetLoaderContext for customization or reference during loading.

    string fileExtension

    Optional. If known, the file extension of the model inside the .zip (e.g., ".fbx"). If null, TriLib attempts to find any recognized 3D file format in the archive.

    bool haltTask

    If true, the loading tasks are created but not started immediately, allowing for manual chaining or scheduling of multiple loads.

    Action<AssetLoaderContext> onPreLoad

    Callback invoked on a background thread before any Unity objects are instantiated. This is useful for performing setup tasks in parallel.

    Returns
    Type Description
    AssetLoaderContext

    An AssetLoaderContext containing references to the loaded model hierarchy and other loading details. Returns null if no suitable model was found in the .zip.

    LoadModelFromZipFileNoThread(string, Action<IContextualizedError>, GameObject, AssetLoaderOptions, object, string)

    Loads the first recognized model file from the specified .zip archive synchronously on the main thread. This method does not utilize background threads or coroutines.

    Declaration
    public static AssetLoaderContext LoadModelFromZipFileNoThread(string path, Action<IContextualizedError> onError = null, GameObject wrapperGameObject = null, AssetLoaderOptions assetLoaderOptions = null, object customContextData = null, string fileExtension = null)
    Parameters
    Type Name Description
    string path

    The file path pointing to the .zip archive.

    Action<IContextualizedError> onError

    Callback invoked on the main thread if any error occurs during extraction or model loading.

    GameObject wrapperGameObject

    Optional parent UnityEngine.GameObject for the resulting model hierarchy.

    AssetLoaderOptions assetLoaderOptions

    The AssetLoaderOptions controlling how the model is loaded.

    object customContextData

    Additional user-defined data stored in the AssetLoaderContext.

    string fileExtension

    Optional. The file extension of the model inside the .zip. If null, TriLib attempts to locate a recognized 3D format automatically.

    Returns
    Type Description
    AssetLoaderContext

    An AssetLoaderContext referencing the loaded model and related data. Returns null if no valid model was found in the .zip.

    LoadModelFromZipStream(Stream, Action<AssetLoaderContext>, Action<AssetLoaderContext>, Action<AssetLoaderContext, float>, Action<IContextualizedError>, GameObject, AssetLoaderOptions, object, string, bool, string, Action<AssetLoaderContext>)

    Loads the first recognized model file found in the given .zip data Stream asynchronously and returns the AssetLoaderContext.

    Declaration
    public static AssetLoaderContext LoadModelFromZipStream(Stream stream, 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 haltTask = false, string modelFilename = null, Action<AssetLoaderContext> onPreLoad = null)
    Parameters
    Type Name Description
    Stream stream

    A Stream containing the .zip data.

    Action<AssetLoaderContext> onLoad

    Callback invoked on the main thread once the model is loaded (but materials may still be pending).

    Action<AssetLoaderContext> onMaterialsLoad

    Callback invoked on the main thread after all materials (textures, shaders, etc.) have finished loading.

    Action<AssetLoaderContext, float> onProgress

    Callback invoked to report loading progress, from 0 to 1.

    Action<IContextualizedError> onError

    Callback invoked on the main thread if any error occurs during .zip extraction or model loading.

    GameObject wrapperGameObject

    Optional parent UnityEngine.GameObject for the resulting model hierarchy. If null, the model loads at the root scene level.

    AssetLoaderOptions assetLoaderOptions

    The AssetLoaderOptions controlling how the model is loaded.

    object customContextData

    User-defined data stored in the AssetLoaderContext for reference.

    string fileExtension

    Optional. The file extension of the model inside the .zip. If null, TriLib attempts to locate a recognized 3D format automatically.

    bool haltTask

    If true, the loading tasks are created but not started immediately.

    string modelFilename

    An optional filename to associate with the model in the AssetLoaderContext. This is useful for logging or reference within TriLib if the .zip data was sourced from a file path.

    Action<AssetLoaderContext> onPreLoad

    A callback invoked on a background thread before any Unity objects are instantiated, allowing parallel setup tasks.

    Returns
    Type Description
    AssetLoaderContext

    An AssetLoaderContext providing references to the loaded model and additional data. Returns null if no suitable model is found in the .zip.

    LoadModelFromZipStreamNoThread(Stream, Action<IContextualizedError>, GameObject, AssetLoaderOptions, object, string)

    Loads the first recognized model file from the specified .zip data Stream synchronously on the main thread. No background threading is used.

    Declaration
    public static AssetLoaderContext LoadModelFromZipStreamNoThread(Stream stream, Action<IContextualizedError> onError, GameObject wrapperGameObject = null, AssetLoaderOptions assetLoaderOptions = null, object customContextData = null, string fileExtension = null)
    Parameters
    Type Name Description
    Stream stream

    A Stream containing the .zip data.

    Action<IContextualizedError> onError

    Callback invoked on the main thread if any error occurs during extraction or model loading.

    GameObject wrapperGameObject

    Optional parent UnityEngine.GameObject for the resulting model hierarchy.

    AssetLoaderOptions assetLoaderOptions

    The AssetLoaderOptions controlling how the model is loaded.

    object customContextData

    Additional user-defined data stored in the AssetLoaderContext.

    string fileExtension

    Optional. The file extension of the model inside the .zip. If null, TriLib attempts to locate a recognized 3D format automatically.

    Returns
    Type Description
    AssetLoaderContext

    An AssetLoaderContext referencing the loaded model and related data.

    ZipFileEntryToStream(out string, ZipEntry, ZipFile)

    Extracts the contents of a given ICSharpCode.SharpZipLib.Zip.ZipEntry into a MemoryStream. The fileExtension is determined from the entry’s filename.

    Declaration
    public static Stream ZipFileEntryToStream(out string fileExtension, ZipEntry zipEntry, ZipFile zipFile)
    Parameters
    Type Name Description
    string fileExtension

    Outputs the extension of the entry’s file (e.g., ".fbx").

    ZipEntry zipEntry

    The ICSharpCode.SharpZipLib.Zip.ZipEntry representing a single file in the archive.

    ZipFile zipFile

    The ICSharpCode.SharpZipLib.Zip.ZipFile containing the zipEntry.

    Returns
    Type Description
    Stream

    A MemoryStream containing the uncompressed data of the zipEntry, rewound to the beginning for immediate reading.

    In this article
    Back to top Generated by DocFX