简体   繁体   English

统一加载资产束时出错

[英]errors loading assetbundle in unity

I'll start with the errors themselves. 我将从错误本身开始。 The first is : Assertion failed on expression: 'm_UncompressedBlocksOffsets[blockInd] <= from + dstPos && m_UncompressedBlocksOffsets[blockInd] + uncompressedBlockSize >= from + dstPos' UnityEngine.AssetBundle:LoadFromFile(String) 第一个是:对表达式的声明失败:'m_UncompressedBlocksOffsets [blockInd] <= from + dstPos && m_UncompressedBlocksOffsets [blockInd] + uncompressedBlockSize> = from + dstPos'UnityEngine.AssetBundle:LoadFromFile(String)

Followed by : Failed to decompress data for the AssetBundle 'D:/Unity/projects/PQv0.10/Assets/AssetBundles/spritesbundle'. 其次:无法为AssetBundle'D:/Unity/projects/PQv0.10/Assets/AssetBundles/spritesbundle'解压缩数据。 UnityEngine.AssetBundle:LoadFromFile(String) UnityEngine.AssetBundle:LoadFromFile(String)

I've always just used the resources folder for my projects but my current project has outgrown what that method can accommodate. 我一直只为我的项目使用资源文件夹,但是我当前的项目已经超出了该方法可以容纳的范围。 So I'm trying to offload assets (in this case 5000 or so sprites)into an assetbundle and load them as needed at runtime. 因此,我试图将资产(在这种情况下为5000个左右的精灵)卸载到资产束中,并在运行时根据需要加载它们。 I figured I could just get a reference to the assetbundle and then call assetbundle.LoadAsset(assetname), substituting my old Resources.Load calls. 我以为我可以得到对assetbundle的引用,然后调用assetbundle.LoadAsset(assetname),用原来的Resources.Load调用代替。 Here's my attempt at making the assetbundle reference that keeps erroring: 这是我尝试制作不断出错的Assetbundle参考的尝试:

AssetBundle sprites;
void loadSprites()
{
    sprites = AssetBundle.LoadFromFile(Application.dataPath + "/AssetBundles/spritesbundle");                //          " + bundleName);
    if (!sprites) {
        Debug.Log("failed to load assetbundle");
    }
}

For due diligence, here's also the code I used to create that assetbundle. 为了尽职调查,这也是我用来创建资产捆绑包的代码。 It simple searches my project for png's and packs them into the assetbundle: 它简单地在我的项目中搜索png并将其打包到assetbundle中:

public static void SaveSpecificAssets()
{
    AssetBundleBuild build = new AssetBundleBuild();
    build.assetBundleName = "spritesBundle";

    string[] files = AssetDatabase.GetAllAssetPaths();
    List<string> validFiles = new List<string>();
    foreach (string file in files)
    {
        if (file.EndsWith(".png")) validFiles.Add(file);
    }

    build.assetNames = validFiles.ToArray();

    BuildPipeline.BuildAssetBundles("Assets/AssetBundles", new AssetBundleBuild[1] { build }, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
}

The assetbundle builds without errors and appears in the directory where it should be. Assetbundle的构建没有错误,并出现在应有的目录中。 I have no indication that it's faulty other than the errors I get when trying to load it. 除了尝试加载它时遇到的错误外,我没有任何迹象表明这是错误的。 The manifest it generates contains appropriate items so I think it's working as intended at least.If I'm missing any relevant information, please point it out and I'll try to provide it. 它生成的清单包含适当的项目,因此我认为它至少可以按预期运行。如果我缺少任何相关信息,请指出来,我将尽力提供。

this is the test coroutine I used in place of loadSprites() for testing if it made a difference: 这是我用来代替loadSprites()的测试协程,它是否有所不同:

IEnumerator testLoader()
{
    WWW www = WWW.LoadFromCacheOrDownload("file:///" + Application.dataPath + "/AssetBundles/spritesbundle", 1);
    yield return www;

    sprites = www.assetBundle;
}

Try this, for all the PNG's in your project folder, select them all and add them to an AssetBundle via the Editor, Then just build using 尝试此操作,对于项目文件夹中的所有PNG,将其全部选中,然后通过编辑器将其添加到AssetBundle,然后使用

BuildPipeline.BuildAssetBundles("Assets/AssetBundles",BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);

Then try to load the bundles and see if it shows an error. 然后尝试加载捆绑软件,看看它是否显示错误。

Also, look into the Manifest to see if all the files you intended are listed 另外,查看清单以查看是否列出了您想要的所有文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM