统一不能加载资产捆绑

时间:2018-09-11 19:10:02

标签: unity3d unityscript assetbundle

我绝对是Unity 3D的初学者。我已经创建了一个.obj 3D模型的资产捆绑包,并将其保存在我的项目文件夹中。现在,我想加载资产束,但是当我点击“播放”时,什么也没发生。这是我用于加载资产捆绑包的代码。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.Networking;

public class NewBehaviourScript : MonoBehaviour
{

    // Use this for initialization
    void Start()
    {
        StartCoroutine(DownloadObject());
    }

    IEnumerator DownloadObject()
    {

        string uri = "file:///" + Application.streamingAssetsPath + "/AssetBundles/" + "stage";
        UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(uri, 0);
        yield return request.SendWebRequest();

        AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request);
        foreach (var name in bundle.GetAllAssetNames())
        {
            Debug.Log(name);
        }
        GameObject stage = bundle.LoadAsset<GameObject>("Stage");

        Instantiate(stage);

    }

    void Update()
    {

    }
}

感谢您的帮助。

谢谢, 莫

0 个答案:

没有答案