I want to download multiple files with different extension file types from the server with unitywebrequest and show progress with progress bar. maybe I need a list or dictionary to add my files URL, but how? I can do it with one file by this code:
public class Tmp_FileDownloader : MonoBehaviour
{
public TextMeshPro m_downloadProgress;
private UnityWebRequest uwr;
public string downloadUrl;
void Start()
{
StartCoroutine(DownloadFile());
}
IEnumerator DownloadFile()
{
var uwr = new UnityWebRequest("http://localhost/1.mp4", UnityWebRequest.kHttpVerbGET);
string path = Path.Combine(Application.persistentDataPath, "1.mp4");
uwr.downloadHandler = new DownloadHandlerFile(path);
StartCoroutine(ShowDownloadProgress(uwr));
yield return uwr.SendWebRequest();
if (uwr.isNetworkError || uwr.isHttpError)
Debug.LogError(uwr.error);
else
{
m_downloadProgress.text = (string.Format("{0:P1}", uwr.downloadProgress));
Debug.Log("File successfully downloaded and saved to " + path);
}
}
public IEnumerator ShowDownloadProgress(UnityWebRequest www)
{
while (!www.isDone)
{
Debug.Log(string.Format("Downloaded {0:P1}", www.downloadProgress));
m_downloadProgress.text = (string.Format("{0:P1}", www.downloadProgress));
yield return new WaitForSeconds(.01f);
}
Debug.Log("Done");
}
}