簡體   English   中英

Assetbundles無法在iOS上使用

[英]Assetbundles not working with iOS

我正在Unity中為iPhone開發一個AR應用程序,該應用程序可從網絡服務器下載資產捆綁包並將其附加到圖像目標。 到目前為止,幾乎所有功能都可以正常工作-除非應用程序嘗試加載資產捆綁包時,出現以下錯誤:

無法加載“資產/捆綁/網址”,因為它不是使用正確的版本或構建目標構建的。

我使用以下腳本創建了資產捆綁包,並從Unity文檔中對其進行了稍微修改:

using UnityEditor;

public class CreateAssetBundles
{
    [MenuItem ("Assets/Build AssetBundles")]
    static void BuildAllAssetBundles ()
    {
        BuildPipeline.BuildAssetBundles ("Assets/AssetBundles", BuildAssetBundleOptions.None, BuildTarget.iOS);
    }
}

然后,我使用scp將資產捆綁包上傳到服務器。 該應用程序可以很好地下載資產捆綁包,但無法加載它們。 這是代碼:

IEnumerator DownloadAndCache (string username, string modelName){
        // Wait for the Caching system to be ready
        while (!Caching.ready) {
            Debug.Log ("Waiting on caching");
            yield return null;
        }

        //Compute request url for server
        UriBuilder uriBuilder = new UriBuilder();
        uriBuilder.Scheme = "http";
        uriBuilder.Host = BaseURL;
        uriBuilder.Path = username.Trim() + "/" + modelName.Trim();
        string BundleURL = uriBuilder.ToString ();
        Debug.Log ("Attempting to download " + BundleURL);

        // Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
        using(WWW www = WWW.LoadFromCacheOrDownload (BundleURL, version)){
            yield return www;
            if (www.error != null) {
                Debug.Log ("Download error");
                throw new Exception ("WWW download had an error:" + www.error);
            }
            AssetBundle bundle = www.assetBundle;
            Debug.Log ("Got assets "+string.Join(",", bundle.GetAllAssetNames ()));
            GameObject loadedModel = Instantiate(bundle.LoadAllAssets()[0]) as GameObject;

            //attach to the image target
            loadedModel.transform.parent = ImageTargetTemplate.gameObject.transform;
            loadedModel.transform.position = new Vector3 (0, 0, 0);
            loadedModel.transform.localScale = new Vector3 (1, 1, 1);

            // Unload the AssetBundles compressed contents to conserve memory
            bundle.Unload(false);

        } // memory is freed from the web stream (www.Dispose() gets called implicitly)
    }

到目前為止,我已經嘗試過:

  • 設置構建目標BuildTarget.iPhone-沒有區別
  • 使用Unity中的assetbundle Manager API構建資產束
  • 在iOS的構建選項中取消選中“條帶引擎代碼”-在另一個論壇上聽說,這可能會導致問題。

任何幫助表示贊賞。

-更新-
我按照程序員的建議修改了BuildAssetBundle腳本,並在播放器設置面板中將目標平台從“ iPhone”切換為“ Universal”。 我很確定這是解決問題的方法。

這意味着在構建資產捆綁包時,您的目標設備不是iOS。 將目標更改為iOS,然后重建資產捆綁包。

重新編譯並重新上傳到iOS,這應該可以解決您的問題。

如果那沒有用,那么...如果在腳本后端設置為IL2CPP的同時構建了AssetBundle,但是隨后將它們與.NET腳本后端一起使用,也會發生該錯誤。 解決方案是在通過播放器設置更改為.NET腳本后端后,重建資產捆綁包。

也可以嘗試更換BuildTarget.iPhoneEditorUserBuildSettings.activeBuildTarget ,使得包會自動建立當前選擇的構建目標。

暫無
暫無

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

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