我正在使用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");
}
}
}发布于 2019-08-05 17:11:34
目标平台Android:
AssetBundles需要构建在目标平台中,稍后将在目标平台上使用它们。由于您希望在安卓中使用AssetBundles,因此在构建AssetBundles时,目标平台也应该是Android。
请同时检查:
您应该在调用UnityWebRequest.SendWebRequest()之前先设置UnityWebRequest.downloadHandler以使用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");
}
}
}https://stackoverflow.com/questions/57354408
复制相似问题