Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Unity 3D:使用AssetBundle动态加载FBX_C#_Unity3d - Fatal编程技术网

C# Unity 3D:使用AssetBundle动态加载FBX

C# Unity 3D:使用AssetBundle动态加载FBX,c#,unity3d,C#,Unity3d,我试图在运行时将一个已经创建的FBX对象加载到场景中,我四处搜索,发现assetbundle可以用于加载。我尝试了这段代码,但它似乎没有实例化场景中的对象,也没有弹出错误 这是密码 using System; using UnityEngine; using System.Collections; public class CachingLoadExample : MonoBehaviour { public string BundleURL; public string As

我试图在运行时将一个已经创建的FBX对象加载到场景中,我四处搜索,发现assetbundle可以用于加载。我尝试了这段代码,但它似乎没有实例化场景中的对象,也没有弹出错误

这是密码

using System;
using UnityEngine;
using System.Collections;

public class CachingLoadExample : MonoBehaviour {
    public string BundleURL;
    public string AssetName;
    public int version;

    void Start() {
        StartCoroutine (DownloadAndCache());
    }

    IEnumerator DownloadAndCache (){
       // Wait for the Caching system to be ready
       while (!Caching.ready)
            yield return null;

        // 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)
                throw new Exception("WWW download had an error:" + www.error);
            AssetBundle bundle = www.assetBundle;
            if (AssetName == "")
                Instantiate(bundle.mainAsset);
            else
                Instantiate(bundle.Load(AssetName));
            // Unload the AssetBundles compressed contents to conserve memory
                    bundle.Unload(false);

        } // memory is freed from the web stream (www.Dispose() gets called implicitly)
    }
}
我添加了一个新的空游戏对象,将C#代码拖到该游戏对象上,提供了资产捆绑链接“file://C:/Users/Sahibzada/Documents/new Unity Project/Assets/100777102370.FBX”,但运气不好


有人能告诉我,代码有什么问题吗?我对Unity中的脚本编写一无所知,谢谢

在您的资产文件夹中创建一个名为AssetBundles的文件夹,然后 您需要使用编辑器脚本创建FBX的资产绑定,如中所示:

最后,您需要在BundleURL中引入新AssetBundle的URL:

"file://C:/Users/Sahibzada/Documents/New Unity Project/Assets/AssetsBundles/yourassetbundle" 
在资产名称上,您需要介绍“您的资产组合”


我还建议不要使用带有空格的路径,这也可能是一个问题。

定义“运气不佳”。什么事情没有按预期发生?您是否看到任何错误消息?你检查控制台了吗?您确定使用的是Unity Pro吗?不会弹出错误,也不会将对象添加到场景中,即我在BundleURL中提到的FBX对象。可能
缓存。isReady
永远不会返回true?另外:你确定你使用的是Unity Pro吗?它是与资产捆绑包一起使用所必需的。
"file://C:/Users/Sahibzada/Documents/New Unity Project/Assets/AssetsBundles/yourassetbundle"