Trilib 运行时导入 - 无法选择对象

问题描述 投票:0回答:1

我正在使用 Trilib 库将运行时的对象导入到我的应用程序中。我单击我编码的导入按钮,从我的电脑中的文件夹中选择模型并将其导入到场景中。

问题是:我想选择该对象来移动它或更改其比例。模型出现在场景中,但您无法访问它。

要使用以下命令进行导入

AssetLoaderContext assetLoaderContext = AssetLoader.LoadModelFromFile(filePath);
正如我所说,模型出现在屏幕上,似乎已加载。但是
assetLoaderContext
是空的,任何访问其变量的尝试都会返回错误。就像它只加载图像一样。

执行

Debug.Log(assetLoaderContext.Models.Count);
时,它返回零,就好像没有加载模型一样,但它是在层次结构中创建的。我还编写了一个 PolyCount() 函数,可以计算屏幕上有多少个多边形,并且在导入模型时它会上升,所以我猜它存在。

我尝试将标签和碰撞器附加到该对象,但我不能,因为它显然不存在。

这是我现在正在使用的代码的一部分

public void ImportModel()
{
    // Open the file selection dialog

    var paths = StandaloneFileBrowser.OpenFilePanel("Select 3d model", "", "", false);

    if(paths != null && paths.Length > 0) 
    {
        string filePath = paths[0];
        AssetLoaderContext assetLoaderContext = AssetLoader.LoadModelFromFile(filePath);
        Debug.Log(assetLoaderContext.Models.Count);

        Dictionary<GameObject, TriLibCore.Interfaces.IModel> hiztegi = assetLoaderContext.Models;
        foreach (var keyValuePair in  hiztegi)
        {
            Debug.Log(keyValuePair.Key);
            loadedModel = keyValuePair.Key;
            break;
        }
         

       Debug.Log(loadedModel);
       if(loadedModel != null)
        
       // assign a tag to be able to edit the object
       AssignTag(loadedModel);

       // attach a mesh collider to the model
       AttachMeshCollider(loadedModel);
        
        else
        {
            Debug.Log("failed to find the root gameobject of the loaded object");
        }
    }


}

是否是使用LoadModelFromFile()时选择的变量错误?

提前致谢。

c# unity-game-engine runtime
1个回答
0
投票

好吧,我只需要使用 trilib 事件,使用 OnLoad 解决了问题。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.