簡體   English   中英

統一加載資產束時出錯

[英]errors loading assetbundle in unity

我將從錯誤本身開始。 第一個是:對表達式的聲明失敗:'m_UncompressedBlocksOffsets [blockInd] <= from + dstPos && m_UncompressedBlocksOffsets [blockInd] + uncompressedBlockSize> = from + dstPos'UnityEngine.AssetBundle:LoadFromFile(String)

其次:無法為AssetBundle'D:/Unity/projects/PQv0.10/Assets/AssetBundles/spritesbundle'解壓縮數據。 UnityEngine.AssetBundle:LoadFromFile(String)

我一直只為我的項目使用資源文件夾,但是我當前的項目已經超出了該方法可以容納的范圍。 因此,我試圖將資產(在這種情況下為5000個左右的精靈)卸載到資產束中,並在運行時根據需要加載它們。 我以為我可以得到對assetbundle的引用,然后調用assetbundle.LoadAsset(assetname),用原來的Resources.Load調用代替。 這是我嘗試制作不斷出錯的Assetbundle參考的嘗試:

AssetBundle sprites;
void loadSprites()
{
    sprites = AssetBundle.LoadFromFile(Application.dataPath + "/AssetBundles/spritesbundle");                //          " + bundleName);
    if (!sprites) {
        Debug.Log("failed to load 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);
}

Assetbundle的構建沒有錯誤,並出現在應有的目錄中。 除了嘗試加載它時遇到的錯誤外,我沒有任何跡象表明這是錯誤的。 它生成的清單包含適當的項目,因此我認為它至少可以按預期運行。如果我缺少任何相關信息,請指出來,我將盡力提供。

這是我用來代替loadSprites()的測試協程,它是否有所不同:

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

    sprites = www.assetBundle;
}

嘗試此操作,對於項目文件夾中的所有PNG,將其全部選中,然后通過編輯器將其添加到AssetBundle,然后使用

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

然后嘗試加載捆綁軟件,看看它是否顯示錯誤。

另外,查看清單以查看是否列出了您想要的所有文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM