gpt4 book ai didi

c# - assetBundle 返回 null

转载 作者:太空宇宙 更新时间:2023-11-03 14:40:09 24 4
gpt4 key购买 nike

我正在使用 UnityWebRequest 从服务器下载 assetBundle,它在 unity 编辑器中运行良好,但在 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:

AssetBundle 需要在稍后使用的目标平台中构建。由于您想在 Android 中使用 AssetBundle,因此当您构建 AssetBundle 时,目标平台 也应该是Android

另请检查:

你应该设置UnityWebRequest.downloadHandler打电话前先UnityWebRequest.SendWebRequest()使用 DownloadHandlerAssetBundle .

    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");
}
}
}

关于c# - assetBundle 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57354408/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com