Unity 2020.3.30f1 中的资产包问题

Problem with Asset Bundles in Unity 2020.3.30f1

我的 Bundle 中包含的对象有问题,因为它是在没有纹理(材质)的情况下实例化的。 现在我会向你解释我做了什么。 我已经将 AssetBundles 浏览器包安装到 unity 中,以使我更容易创建 AssetBundles。 我创建了一个名为“Cheese2”的预制件,其中包含一些组件

This is the inspector of the object

我创建了一个名为“test2”的新 AssetBundle

在此之后,我查看了 AssetBundle 浏览器,我看到 AssetBundle 已正确配置了所有依赖项(AssetBundles 浏览器自动包含对象的所有依赖项)

This is the AssetBundles Browser windows with my Bundle "test2" and all the Assets

好的,在此之后我将捆绑包构建到我的文件夹“StreamingAssets”中并已创建 some files

现在该看剧本了:

public void Evoca()
    {

    var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "test2"));
    
    if (myLoadedAssetBundle == null)
    {
        Debug.Log("Failed to load AssetBundle!");
        return;
    }
    
    var prefab = myLoadedAssetBundle.LoadAsset<GameObject>("Cheese2.prefab");
    Instantiate(prefab, transform.position + (transform.forward * 1), Quaternion.identity);

}

你怎么看我已经为 select 捆绑包创建了一个名为“myLoadedAssetBundle”的变量,并为 select 我要实例化的捆绑包的哪些资产创建了一个名为“prefab”的变量(在这种情况下是 Cheese2.prefab),在此之后,我实例化了资产 Cheese2.prefab.

我按下按钮调用函数“Evoca”(用于实例化 AssetBundle 的函数),但是 result is this。

你怎么能看到我的奶酪没有纹理,我不明白为什么。 附加到我的组件的“脚本”和“盒子碰撞器”工作正常。

我刚刚尝试创建另一个名为“dependencies”的 AssetBundle,其中包含我对象的所有依赖项,并在加载“test2”之前对其进行预充电 (accordly to the unity manual)

像这样:

    public void Evoca()
{
    var dependencies= AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "dependencies"));
    
    var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "test2"));
    
    Debug.Log(dependencies);
    if (dependencies== null)
    {
        Debug.Log("There is a problem with your dependencies!");
        return;
    }
    if (myLoadedAssetBundle == null)
    {
        Debug.Log("Failed to load AssetBundle!");
        return;
    }
    
    var prefab = myLoadedAssetBundle.LoadAsset<GameObject>("Cheese2.prefab");
    Instantiate(prefab, transform.position + (transform.forward * 1), Quaternion.identity);
    
}

但是没用。

有人可以帮助我吗?

我找到了解决方案。 问题出在统一“游戏”模拟器上,我在 reddit 上看到 this post,我想“等等,如果我在我的 phone 上尝试应用程序,它能正常工作吗?”。 答案是肯定的,在我的 Phone 上它工作正常并且所有纹理都由资产负责。