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# assetBundle返回null_C#_Unity3d - Fatal编程技术网

C# assetBundle返回null

C# assetBundle返回null,c#,unity3d,C#,Unity3d,我正在使用UnityWebRequest从服务器下载assetBundle,它在UnityEditor中运行良好,但在andriod中它提供空值。有人能帮我吗 public IEnumerator DownloadAsset(string url, string assetName) { using (UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(url)) { yield retu

我正在使用UnityWebRequest从服务器下载assetBundle,它在UnityEditor中运行良好,但在andriod中它提供空值。有人能帮我吗

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");
        }
    }
}
目标平台Android: 资产绑定需要构建在目标平台中,以便以后使用。 由于您希望在Android中使用AssetBundles,因此在构建AssetBundles时,目标平台也应该是Android

请同时检查:

您应该在调用之前先设置以使用

public System.Collections.IEnumerator下载资产(字符串url,字符串assetName)
{
使用(var uwr=new UnityEngine.Networking.UnityWebRequest(url,UnityEngine.Networking.UnityWebRequest.kHttpVerbGET))
{
uwr.downloadHandler=new UnityEngine.Networking.DownloadHandlerAssetBundle(url,0);
产生返回uwr.SendWebRequest();
AssetBundle bundle=UnityEngine.Networking.DownloadHandlerAssetBundle.GetContent(uwr);
if(bundle!=null)
{
AGUIMisc.showtoos(“非空”);
游戏对象温度=bundle.LoadAsset(assetName);
var newobj=GameObject.Instantiate(temp);
newobj.transform.parent=maleparent.transform;
}
其他的
{
AGUIMisc.showtoos(“空”);
}
}
}

您是否尝试登录www.error以查看下载时是否出现任何错误?否让我检查,我会让您知道www.error中没有错误我会在检查相同问题后让您知道!它在unity editor中运行良好,但在andriod中,bundle值为null@Beautyfull CastleId您为Android构建资产bundles目标平台吗?
    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");
            }
        }
    }