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
Dynamic 从AssetBundle加载Unity游戏场景_Dynamic_Unity3d_Scene_Assetbundle - Fatal编程技术网

Dynamic 从AssetBundle加载Unity游戏场景

Dynamic 从AssetBundle加载Unity游戏场景,dynamic,unity3d,scene,assetbundle,Dynamic,Unity3d,Scene,Assetbundle,我尝试使用以下代码从AssetBundle加载Unity场景: using (WWW www = WWW.LoadFromCacheOrDownload("http://127.0.0.1:8080/unity/test-scene", 1)) { yield return www; if (www.error != null) { Debug.Log("Load Error " + www.error); } AssetBundle b

我尝试使用以下代码从AssetBundle加载Unity场景:

using (WWW www = WWW.LoadFromCacheOrDownload("http://127.0.0.1:8080/unity/test-scene", 1))
{
    yield return www;
    if (www.error != null)
    {
        Debug.Log("Load Error " + www.error);
    }

    AssetBundle bundle = www.assetBundle;
    Object[] loadObjectList = bundle.LoadAllAssets();

    foreach(Object tempObj in loadObjectList)
    {
        Debug.Log("Object = " + tempObj);
    }
}
对于场景基本捆绑包,我总是为
loadObjectList
数组获取0个元素

如果调用
bundle.getAllScenePath()
函数,我会得到场景路径,但如果我尝试使用
SceneManager.LoadScene()函数加载这些场景,我会收到以下错误消息:

“(-1)无法加载场景,因为尚未将其添加到生成设置或未加载AssetBundle”


是否有人知道如何从AssetBundle加载场景,或者这是统一性的限制?

最后,我找到了方法:如果我为
LoadScene()
函数指定路径和文件扩展名,它可能会失败

例如:

SceneManager.LoadScene(“Assets/demosc1.unity”)不工作,产生上述错误。这需要修改为
SceneManager.LoadScene(“demosc1”)