About loading models, the use of TriLib plug-ins

Loading model plugin version number: TriLib 2 - Model Loading Package 2.1.6

Import the plugin into unity

All functions included in this plugin can be viewed in the scene AssetViewer.

Key API for loading models: AssetLoader.LoadModelFromFile

Key script: load the model according to the path

public void LoadFBXClick(string path)
    {
       var assetLoaderOptions = AssetLoader.CreateDefaultLoaderOptions();
       AssetLoader.LoadModelFromFile(path, OnLoad, OnMaterialsLoad, OnProgress, OnError, parents, assetLoaderOptions);
    }
 

The parameters indicate:

path, the absolute path of the model to be loaded, cannot be empty

Definition: string

OnLoad, when the model is loaded, the material has not been loaded at this time, it can be empty

definition:

private void OnLoad(AssetLoaderContext assetLoaderContext)
    {
        Debug.Log("加载的模型名称"+assetLoaderContext.RootGameObject.name);
    }

OnMaterialsLoad, when the model material is loaded, that is, when the entire model is loaded, it can be empty

definition:

private void OnMaterialsLoad(AssetLoaderContext assetLoaderContext)
    {
         Debug.Log("加载完成");
    }

OnProgress, model loading progress, can be empty

definition:

private void OnProgress(AssetLoaderContext assetLoaderContext, float progress)
    {
        Debug.Log($"正在加载模型,进度为: {progress:P}");
    }

OnError, an error occurred while loading the model, can be empty

definition:

private void OnError(IContextualizedError obj)
        {
            Debug.LogError($"An error occurred while loading your Model: {obj.GetInnerException()}");
        }

parents, the parent object of the loaded model, can be empty

Definition: GameObject

Note: The texture of the model needs to be in the same folder as the model, so that the loading of the material can be completed

Guess you like

Origin blog.csdn.net/Sheldonononon/article/details/129306173
Recommended