首页 文章

Unity - 加载资产包 - 无法加载文件,因为它与此平台不兼容

提问于
浏览
0

我正在使用Unity应用程序加载来自我的htdocs的资产包,一个可以在iPhone上运行的资产包 .

当内容获取工作(afaik)时,加载停止大约一半,Xcode吐出以下错误:

Unloading 3 Unused Serialized files (Serialized files now loaded: 0)
UnloadTime: 13.037000 ms

Unloading 50 unused Assets to reduce memory usage. Loaded Objects now: 733.
Total: 10.006415 ms (FindLiveObjects: 0.065750 ms CreateObjectMapping: 0.033250 ms MarkObjects: 0.951208 ms  DeleteObjects: 8.955166 ms)

2016-10-26 18:34:58.882 CookieJarApp[6245:1953469] You are using download over http. Currently unity adds NSAllowsArbitraryLoads to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https.
Asset bundle [ios_cookie_prefabs] loaded.
<CoLoadAssetBundle>d__20:MoveNext()

(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

The file can not be loaded because it was created for another build target that is not compatible with this platform.
Please make sure to build AssetBundles using the build target platform that it is used by.
File's Build target is: 13

<CoLoadAssetBundle>d__20:MoveNext()

[ line 907] 
(Filename:  Line: 907)

The AssetBundle 'http://192.168.1.241:80/CookieJarApp_test/ios_cookie_prefabs' can't be loaded because it was not built with the right version or build target.
<CoLoadAssetBundle>d__20:MoveNext()

[ line 406] 
(Filename:  Line: 406)

NullReferenceException: A null value was found where an object instance was required.
  at AssetBundleController.GetGameObject (System.String bundleID, System.String objectName) [0x00000] in <filename unknown>:0 
  at AssetBundleController.UnloadAll () [0x00000] in <filename unknown>:0 
  at Loader+<LoadPrefabs>c__AnonStorey22.<>m__15 (UnityEngine.AssetBundle bundle) [0x00000] in <filename unknown>:0 
  at AssetBundleController+<CoLoadAssetBundle>d__20.MoveNext () [0x00000] in <filename unknown>:0 

(Filename: currently not available on il2cpp Line: -1)

但是,我使用在Build Settings中选择的iOS平台构建了预制件(本身就是另一个游戏) .

我被告知资产包的不同之处,还有什么我可以尝试的吗?

这是 CoLoadAssetBundle 函数:

// Start a download of the given URL
        WWW www = new WWW(url);

        while (!www.isDone)
        {
            Debug.Log("[" + bundleId + "] Progress:" + www.progress * 100f + "%");
            yield return null;
        }

        if (string.IsNullOrEmpty(www.error))
        {
            Debug.Log("Asset bundle [" + bundleId + "] loaded.");
            m_assetBundleList.Add(new AssetBundleStruct(bundleId, www.assetBundle));
        }
        else
        {
            Debug.Log("Asset bundle [" + bundleId + "] not loaded!\n[" + www.error + "]");
        }

        www.Dispose();

1 回答

  • 1

    在为iOS构建之后,您必须强制缓存使用 AssetBundle 的新副本 .

    如果使用WWW API,则可以通过提供第二个参数( int version )来执行此操作 .

    WWW.LoadFromCacheOrDownload(url, 1);
    

    如果使用UnityWebRequest API,则必须向其静态构造函数提供第三个参数( uint version ) .

    UnityWebRequest www = UnityWebRequest.GetAssetBundle(url, 0, 1);
    

    EDIT

    使用您编辑的问题和代码,您需要使用我在本答案中提到的第一种方法 . 只需更换

    WWW www = new WWW(url); with WWW www = WWW.LoadFromCacheOrDownload(url, 1);

相关问题