Documentation says about ReceiveData function:
“This function requires a return value of either true or false. If you return false, the system immediately aborts the UnityWebRequest. If you return true, processing continues normally.”
What is natural way to continue process / dispose UnityWebRequest instance after ReceiveData return false?
I experimented and find out if ReceiveData return false process never reach code after yield.
public class LoggingDownloadHandler : DownloadHandlerScript
{
//...
int i = 1;
protected override bool ReceiveData(byte[] data, int dataLength)
{
if (data == null || data.Length < 1 || i == 5)
return false;
i++;
return true;
}
}
public class Downloader : MonoBehaviour
{
void Start()
{
StartCoroutine(LoadFromWeb("my_real_url"));
}
IEnumerator LoadFromWeb(string url)
{
UnityWebRequest wr = new UnityWebRequest(url);
LoggingDownloadHandler handler = new LoggingDownloadHandler();
wr.downloadHandler = handler;
yield return wr.Send();
if (!wr.isError)
{
//...
}
wr.Dispose();
}
}