TriLib
Search Results for

    Show / Hide Table of Contents

    Class AssetLoaderContext

    Serves as the central context for managing a model loading operation in TriLib. This class stores references to the loaded objects (GameObjects, textures, materials), user options, callbacks, and intermediate state (e.g., asynchronous tasks, in-flight texture loads).

    Inheritance
    object
    AssetLoaderContext
    Implements
    IAssetLoaderContext
    IAwaitable
    Inherited Members
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: TriLibCore
    Assembly: TriLibCore.dll
    Syntax
    public class AssetLoaderContext : IAssetLoaderContext, IAwaitable

    Constructors

    AssetLoaderContext()

    Declaration
    public AssetLoaderContext()

    Fields

    Allocations

    A list of Unity objects (e.g., UnityEngine.Texture2D, UnityEngine.Material, UnityEngine.Mesh) that have been allocated during the model loading process.

    Declaration
    public readonly List<Object> Allocations
    Field Value
    Type Description
    List<Object>

    AppliedDoubleSidedMaterials

    Indicates whether double-sided materials (i.e., materials requiring backside rendering) were applied to the last processed mesh. This can help track special mesh rendering states.

    Declaration
    public bool AppliedDoubleSidedMaterials
    Field Value
    Type Description
    bool

    Async

    If true, the model loads asynchronously whenever possible. If false, TriLib forces a synchronous approach. This affects how tasks and threads are used.

    Declaration
    public bool Async
    Field Value
    Type Description
    bool

    BasePath

    The directory or base path from which the model or resources are loaded. Used for finding external textures or other data.

    Declaration
    public string BasePath
    Field Value
    Type Description
    string

    CancellationToken

    A token used to manage the timeout or cancellation of the loading process. If triggered, loading tasks are halted before completion.

    Declaration
    public CancellationToken CancellationToken
    Field Value
    Type Description
    CancellationToken

    CancellationTokenSource

    A source object that can be invoked to cancel model loading manually (e.g., by user input). Cancels tasks reliant on CancellationToken.

    Declaration
    public CancellationTokenSource CancellationTokenSource
    Field Value
    Type Description
    CancellationTokenSource

    CustomData

    Arbitrary user-defined data or metadata attached to this context. This object can store additional loading parameters, usage info, or placeholders needed by custom logic.

    Declaration
    public object CustomData
    Field Value
    Type Description
    object

    FileExtension

    When loading from a stream rather than a local file, this stores the file extension (e.g., "fbx", "gltf") so TriLib can determine an appropriate reader or parser.

    Declaration
    public string FileExtension
    Field Value
    Type Description
    string

    Filename

    When loading from the local file system, this indicates the path or filename to load. This may be combined with BasePath for resource lookups.

    Declaration
    public string Filename
    Field Value
    Type Description
    string

    GameObjectPaths

    A mapping between created UnityEngine.GameObjects and their hierarchy paths within the loaded model (e.g., “Root/Mesh001”). This is useful for tracking or debugging the final hierarchy after import.

    Declaration
    public readonly Dictionary<GameObject, string> GameObjectPaths
    Field Value
    Type Description
    Dictionary<GameObject, string>

    GameObjects

    A mapping between TriLib model representations (IModel) and the corresponding UnityEngine.GameObjects created for them in Unity.

    Declaration
    public readonly Dictionary<IModel, GameObject> GameObjects
    Field Value
    Type Description
    Dictionary<IModel, GameObject>

    GeneratedMaterials

    A thread-safe dictionary mapping TriLib materials (IMaterial) to Unity UnityEngine.Material objects generated on-the-fly. This can be used to look up or reuse already created materials.

    Declaration
    public readonly ConcurrentDictionary<IMaterial, Material> GeneratedMaterials
    Field Value
    Type Description
    ConcurrentDictionary<IMaterial, Material>

    HaltTasks

    If true, TriLib defers the actual start of loading tasks, letting the user or calling code chain multiple tasks or manually schedule the execution.

    Declaration
    public bool HaltTasks
    Field Value
    Type Description
    bool

    HandleError

    A delegate for internal error handling, invoked before OnError. This allows additional checks or logging prior to the user-facing error callback.

    Declaration
    public Action<IContextualizedError> HandleError
    Field Value
    Type Description
    Action<IContextualizedError>

    IsZipFile

    If true, indicates that the current loading operation involves a .zip file, requiring AssetLoaderZip or related logic to decompress and parse contents.

    Declaration
    public bool IsZipFile
    Field Value
    Type Description
    bool

    LoadedCompoundTextures

    A thread-safe dictionary storing compound textures keyed by a CompoundTextureKey, which represents the texture plus its usage type (e.g., diffuse, normal, metallic). Each entry references the TextureLoadingContext used to load that texture.

    Declaration
    public readonly ConcurrentDictionary<CompoundTextureKey, TextureLoadingContext> LoadedCompoundTextures
    Field Value
    Type Description
    ConcurrentDictionary<CompoundTextureKey, TextureLoadingContext>

    LoadedExternalData

    A thread-safe dictionary that maps shortened external resource filenames to their fully resolved paths on disk or elsewhere.

    Declaration
    public readonly ConcurrentDictionary<string, string> LoadedExternalData
    Field Value
    Type Description
    ConcurrentDictionary<string, string>

    LoadedMaterials

    A thread-safe dictionary linking TriLib materials (IMaterial) to the generated Unity UnityEngine.Material objects. This complements GeneratedMaterials in storing final user-facing materials.

    Declaration
    public readonly ConcurrentDictionary<IMaterial, Material> LoadedMaterials
    Field Value
    Type Description
    ConcurrentDictionary<IMaterial, Material>

    LoadedTextures

    A thread-safe dictionary mapping TriLib textures (ITexture) to their TextureLoadingContext results, used to prevent redundant texture loading and allow reuse where possible.

    Declaration
    public readonly ConcurrentDictionary<ITexture, TextureLoadingContext> LoadedTextures
    Field Value
    Type Description
    ConcurrentDictionary<ITexture, TextureLoadingContext>

    LoadingProgress

    Tracks the overall progress of model loading (a float between 0 and 1).

    Declaration
    public float LoadingProgress
    Field Value
    Type Description
    float

    LoadingStep

    Represents the loading step (an integer) for more granular tracking of progress (e.g., reading geometry, loading textures, building materials).

    Declaration
    public int LoadingStep
    Field Value
    Type Description
    int

    MaterialRenderers

    A thread-safe dictionary linking TriLib materials (IMaterial) to their MaterialRendererContext objects, which contain references to the Unity renderer and geometry data needing that material.

    Declaration
    public readonly ConcurrentDictionary<IMaterial, List<MaterialRendererContext>> MaterialRenderers
    Field Value
    Type Description
    ConcurrentDictionary<IMaterial, List<MaterialRendererContext>>

    MaterialTextures

    A thread-safe dictionary linking a CompoundMaterialKey (material + texture type) to the loaded TextureLoadingContext. This ensures that a texture used in multiple material slots is loaded or referenced consistently.

    Declaration
    public readonly ConcurrentDictionary<CompoundMaterialKey, TextureLoadingContext> MaterialTextures
    Field Value
    Type Description
    ConcurrentDictionary<CompoundMaterialKey, TextureLoadingContext>

    Models

    A mapping between UnityEngine.GameObjects created during loading and the corresponding TriLib IModel representations (e.g., for referencing raw geometry data).

    Declaration
    public readonly Dictionary<GameObject, IModel> Models
    Field Value
    Type Description
    Dictionary<GameObject, IModel>

    ModificationDate

    Potentially stores a file modification date or version retrieved by format-specific data. This may be used for caching or informational displays.

    Declaration
    public string ModificationDate
    Field Value
    Type Description
    string

    OnError

    A callback invoked on the main thread if an error occurs during loading. Often used to notify the user or perform cleanup tasks.

    Declaration
    public Action<IContextualizedError> OnError
    Field Value
    Type Description
    Action<IContextualizedError>

    OnLoad

    A callback invoked once the model’s core structure is loaded, but possibly before all textures and materials finish processing. This occurs on the main thread.

    Declaration
    public Action<AssetLoaderContext> OnLoad
    Field Value
    Type Description
    Action<AssetLoaderContext>

    OnMaterialsLoad

    A callback invoked once the model and all relevant resources (e.g., textures, materials, animations) have finished loading. Called on the main thread.

    Declaration
    public Action<AssetLoaderContext> OnMaterialsLoad
    Field Value
    Type Description
    Action<AssetLoaderContext>

    OnPreLoad

    A callback invoked on a background thread, providing a chance to manipulate or inspect data before Unity UnityEngine.GameObjects are instantiated (only when multi-threading is enabled).

    Declaration
    public Action<AssetLoaderContext> OnPreLoad
    Field Value
    Type Description
    Action<AssetLoaderContext>

    OnProgress

    A callback that reports loading progress changes, providing both the current AssetLoaderContext and a float progress value (0–1).

    Declaration
    public Action<AssetLoaderContext, float> OnProgress
    Field Value
    Type Description
    Action<AssetLoaderContext, float>

    Options

    The AssetLoaderOptions governing how the model is imported (e.g., whether to generate colliders, import animations, or apply custom material mappers).

    Declaration
    public AssetLoaderOptions Options
    Field Value
    Type Description
    AssetLoaderOptions

    PreviousLoadingStep

    Tracks the previously reported loading step, aiding in detecting changes for incremental updates or logging. Defaults to -1 to indicate uninitialized.

    Declaration
    public int PreviousLoadingStep
    Field Value
    Type Description
    int

    Reader

    References the internal ReaderBase that’s parsing or converting the file. Specific implementations (e.g., FBXReader, GltfReader) fill in data for geometry, bones, and materials.

    Declaration
    public ReaderBase Reader
    Field Value
    Type Description
    ReaderBase

    RootGameObject

    The UnityEngine.GameObject representing the top-level node of the loaded model. Contains or references all other child meshes, transforms, and data.

    Declaration
    public GameObject RootGameObject
    Field Value
    Type Description
    GameObject

    RootModel

    An interface representing the root model structure (IRootModel) of the loaded file. It can contain sub-models, materials, animations, etc.

    Declaration
    public IRootModel RootModel
    Field Value
    Type Description
    IRootModel

    Stream

    The Stream used to load the model if loading from memory or network data rather than a filesystem path.

    Declaration
    public Stream Stream
    Field Value
    Type Description
    Stream

    Task

    A reference to the main Task used for the loading operation (if asynchronous). This allows for concurrency and non-blocking behavior during model import.

    Declaration
    public Task Task
    Field Value
    Type Description
    Task

    Tasks

    A list of Task instances related to this loading operation, used to manage parallel or sequential tasks (texture loading, post-processing, etc.).

    Declaration
    public List<Task> Tasks
    Field Value
    Type Description
    List<Task>

    TexturesWithAlphaChecked

    Tracks whether particular UnityEngine.Texture objects have already been checked for alpha channels, avoiding repeated checks or overhead.

    Declaration
    public readonly Dictionary<Texture, bool> TexturesWithAlphaChecked
    Field Value
    Type Description
    Dictionary<Texture, bool>

    UsedTextures

    Keeps a set of textures that have been successfully applied to renderers, which helps differentiate between used and unused textures (for optional discarding of unused ones).

    Declaration
    public readonly HashSet<Texture> UsedTextures
    Field Value
    Type Description
    HashSet<Texture>

    WrapperGameObject

    A user-specified or automatically created UnityEngine.GameObject that serves as the parent object for the entire loaded model hierarchy.

    Declaration
    public GameObject WrapperGameObject
    Field Value
    Type Description
    GameObject

    Properties

    Completed

    If true, indicates that the model loading process has finished, including asynchronous tasks. If false, the pipeline is still in progress.

    Declaration
    public bool Completed { get; set; }
    Property Value
    Type Description
    bool

    CustomDispatcherQueue

    A queue holding context-specific actions that can be dispatched on the main thread or processed in other contexts. Useful for advanced customization or specialized event scheduling.

    Declaration
    public Queue<IContextualizedAction> CustomDispatcherQueue { get; }
    Property Value
    Type Description
    Queue<IContextualizedAction>

    PersistentDataPath

    The Application.persistentDataPath or another user-defined path for storing or retrieving extracted or cached resources (e.g., embedded textures).

    Declaration
    public string PersistentDataPath { get; set; }
    Property Value
    Type Description
    string

    Methods

    AddMaterialTexture(TextureLoadingContext)

    Records a newly loaded texture’s context in MaterialTextures to track the usage of that texture by a specific material/slot combination.

    Declaration
    public void AddMaterialTexture(TextureLoadingContext textureLoadingContext)
    Parameters
    Type Name Description
    TextureLoadingContext textureLoadingContext

    The TextureLoadingContext holding the TriLib texture and additional metadata.

    AddUsedTexture(Texture)

    Marks a UnityEngine.Texture as used by at least one renderer or material, so TriLib knows not to discard it when cleaning up unused allocations.

    Declaration
    public void AddUsedTexture(Texture texture)
    Parameters
    Type Name Description
    Texture texture

    The texture being used by a model’s material.

    DiscardUnusedTextures()

    Removes any UnityEngine.Texture that isn’t referenced in UsedTextures from the Allocations list and destroys it, freeing memory. Useful if your model has optional or generated textures that are never applied.

    Declaration
    public void DiscardUnusedTextures()

    ReleaseMainThread()

    Yields execution back to Unity if UseCoroutines is enabled, preventing long blocking operations on the main thread. Exits immediately if coroutines are disabled.

    Declaration
    public IEnumerable ReleaseMainThread()
    Returns
    Type Description
    IEnumerable

    An IEnumerable that yields once if the elapsed time since the last yield exceeded MaxCoroutineDelayInMS, otherwise yields nothing.

    Setup()

    Performs initial setup for this loader context, such as preparing a Stopwatch for timing coroutine yields if UseCoroutines is true.

    Declaration
    public void Setup()

    TryGetCompoundTexture(TextureLoadingContext, out TextureLoadingContext)

    Checks whether a texture with the specified TextureLoadingContext already exists in LoadedCompoundTextures. If found, reuses the existing data to avoid duplicating memory or I/O.

    Declaration
    public bool TryGetCompoundTexture(TextureLoadingContext textureLoadingContext, out TextureLoadingContext existingTextureLoadingContext)
    Parameters
    Type Name Description
    TextureLoadingContext textureLoadingContext

    Contains references to the TriLib texture, texture type, and the pipeline context.

    TextureLoadingContext existingTextureLoadingContext

    An output parameter set to the found TextureLoadingContext, if any.

    Returns
    Type Description
    bool

    true if the texture was found, otherwise false.

    TryGetLoadedTexture(TextureLoadingContext, out TextureLoadingContext)

    Checks whether the specified TriLib ITexture is already listed in LoadedTextures. If found, reuses its TextureLoadingContext so no redundant loading is performed.

    Declaration
    public bool TryGetLoadedTexture(TextureLoadingContext textureLoadingContext, out TextureLoadingContext existingTextureLoadingContext)
    Parameters
    Type Name Description
    TextureLoadingContext textureLoadingContext

    Contains the TriLib texture reference.

    TextureLoadingContext existingTextureLoadingContext

    Output parameter set to the found TextureLoadingContext, if any.

    Returns
    Type Description
    bool

    true if the texture was previously loaded, otherwise false.

    TryGetMaterialTexture(IMaterial, TextureType, out Texture)

    Searches for a processed texture (already loaded and stored) based on the given material and texture type. If found, sets loadedTexture and returns true.

    Declaration
    public bool TryGetMaterialTexture(IMaterial material, TextureType textureType, out Texture loadedTexture)
    Parameters
    Type Name Description
    IMaterial material

    The source TriLib material.

    TextureType textureType

    A TextureType indicating diffuse, normal, etc.

    Texture loadedTexture

    The Unity UnityEngine.Texture that was found, or null if none exists.

    Returns
    Type Description
    bool

    true if a texture was found, false if not.

    TryRegisterTexture(TextureLoadingContext)

    Called to register a new TextureLoadingContext or reuse an existing one if the same texture reference is found. This avoids duplicate loads and ensures consistent texture usage across multiple materials or submeshes.

    Declaration
    public void TryRegisterTexture(TextureLoadingContext textureLoadingContext)
    Parameters
    Type Name Description
    TextureLoadingContext textureLoadingContext

    The TextureLoadingContext describing the texture, type, and pipeline context.

    Implements

    IAssetLoaderContext
    IAwaitable

    Extension Methods

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