2016-03-06 44 views
1

我正在为Unity开发AR应用程序,该应用程序从Web服务器下载资产捆绑并将它们附加到图像目标。到目前为止,几乎所有的工作 - 只是,当应用程序试图加载的资产包,我得到以下错误:不与iOS配合使用的资产捆绑

'asset/bundle/url' can't be loaded because it was not built with the right version or build target.

我创建使用下面的脚本assetbundles,从团结的文档略作修改:

using UnityEditor; 

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

然后我使用scp将assetsbundles上传到服务器。该应用下载的资产捆绑很好,但无法加载它们。下面的代码:

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管理API的assetbundles iOS中的构建选项中的“strip engine code” - 我在另一个论坛上听到这可能会导致问题。

任何帮助表示赞赏。

-UPDATE-
我根据程序员的建议修改了BuildAssetBundle脚本,并在播放器设置面板中将目标平台从“iPhone”切换到“Universal”。我很确定这是解决问题的方法。

回答

4

这意味着当您构建资源包时,您的目标设备不是iOS。将目标更改为iOS,然后重建资产包。

重新编译并重新上传到iOS,并应该解决您的问题。

如果没有效果,那么...... 如果您在脚本后端设置为IL2CPP时构建了AssetBundle,但随后将它们与.NET脚本后端一起使用,那么该错误也会发生。解决方案是在通过播放器设置更改为.NET脚本后端后重建您的Asset Bundle。

也可以尝试用BuildTarget.iPhone替换EditorUserBuildSettings.activeBuildTarget,以便该Bundle可以自动为当前选定的任何构建目标构建。