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.
Inherited Members
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 TriLibCore.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 TriLibCore.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 |
AssetLoaderOptions | assetLoaderOptions | The TriLibCore.AssetLoaderOptions controlling how the model is loaded (e.g., material/texture mappers, animation settings). |
object | customContextData | User-defined data to store in the TriLibCore.AssetLoaderContext for customization or reference during loading. |
string | fileExtension | Optional. If known, the file extension of the model inside the .zip (e.g., |
bool | haltTask | If |
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 TriLibCore.AssetLoaderContext containing references to the loaded model hierarchy
and other loading details. Returns |
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 TriLibCore.AssetLoaderOptions controlling how the model is loaded. |
object | customContextData | Additional user-defined data stored in the TriLibCore.AssetLoaderContext. |
string | fileExtension | Optional. The file extension of the model inside the .zip. If |
Returns
Type | Description |
---|---|
AssetLoaderContext | An TriLibCore.AssetLoaderContext referencing the loaded model and related data.
Returns |
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 TriLibCore.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 |
AssetLoaderOptions | assetLoaderOptions | The TriLibCore.AssetLoaderOptions controlling how the model is loaded. |
object | customContextData | User-defined data stored in the TriLibCore.AssetLoaderContext for reference. |
string | fileExtension | Optional. The file extension of the model inside the .zip. If |
bool | haltTask | If |
string | modelFilename | An optional filename to associate with the model in the TriLibCore.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 TriLibCore.AssetLoaderContext providing references to the loaded model
and additional data. Returns |
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 TriLibCore.AssetLoaderOptions controlling how the model is loaded. |
object | customContextData | Additional user-defined data stored in the TriLibCore.AssetLoaderContext. |
string | fileExtension | Optional. The file extension of the model inside the .zip. If |
Returns
Type | Description |
---|---|
AssetLoaderContext | An TriLibCore.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., |
ZipEntry | zipEntry | The ICSharpCode.SharpZipLib.Zip.ZipEntry representing a single file in the archive. |
ZipFile | zipFile | The ICSharpCode.SharpZipLib.Zip.ZipFile containing the |
Returns
Type | Description |
---|---|
Stream | A MemoryStream containing the uncompressed data of the |