首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >assetBundle返回null

assetBundle返回null
EN

Stack Overflow用户
提问于 2019-08-05 15:57:05
回答 1查看 565关注 0票数 2

我正在使用UnityWebRequest从服务器下载assetBundle,它在unity编辑器中运行良好,但在andriod中它给出了空值,有人能帮助我吗

代码语言:javascript
复制
public IEnumerator DownloadAsset(string url, string assetName)
{
    using (UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(url))
    {
        yield return www.SendWebRequest();
        AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);
        if (bundle != null)
        {
            AGUIMisc.ShowToast("Not Null");
            GameObject temp = bundle.LoadAsset(assetName) as GameObject;
            var newobjj = Instantiate(temp);
            newobjj.transform.parent = maleparent.transform;
        }
        else
        {
            AGUIMisc.ShowToast("Null");
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2019-08-05 17:11:34

目标平台Android:

AssetBundles需要构建在目标平台中,稍后将在目标平台上使用它们。由于您希望在安卓中使用AssetBundles,因此在构建AssetBundles时,目标平台也应该是Android。

请同时检查:

您应该在调用UnityWebRequest.SendWebRequest()之前先设置UnityWebRequest.downloadHandler以使用DownloadHandlerAssetBundle

代码语言:javascript
复制
    public System.Collections.IEnumerator DownloadAsset(string url, string assetName)
    {
        using (var uwr = new UnityEngine.Networking.UnityWebRequest(url, UnityEngine.Networking.UnityWebRequest.kHttpVerbGET))
        {
            uwr.downloadHandler = new UnityEngine.Networking.DownloadHandlerAssetBundle(url, 0);
            yield return uwr.SendWebRequest();
            AssetBundle bundle = UnityEngine.Networking.DownloadHandlerAssetBundle.GetContent(uwr);
            if (bundle != null)
            {
                AGUIMisc.ShowToast("Not Null");
                GameObject temp = bundle.LoadAsset<GameObject>(assetName);
                var newobj = GameObject.Instantiate(temp);
                newobj.transform.parent = maleparent.transform;
            }
            else
            {
                AGUIMisc.ShowToast("Null");
            }
        }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57354408

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档