Wie habe ich mehrere Downloads nacheinander abgeschlossen, während das Headset vom Benutzer des Benutzers ist?C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Wie habe ich mehrere Downloads nacheinander abgeschlossen, während das Headset vom Benutzer des Benutzers ist?

Post by Anonymous »

Verwenden von Unity Web Request kann ich einen Download starten, das Quest -Headset abnehmen und dieser Download wird fertig sein. Es wird den nächsten Download nicht speichern oder starten. Wie könnte ich das schaffen? Entweder indem das Headset wach bleibt oder Skripte ausgeführt wird, obwohl das Headset ausgeschaltet wurde.

Code: Select all

IEnumerator DownloadAllVideosSequentially()
{
//count how many missing files
//TODO: Maybe it would be better to store this earlier on than loop through the videos again

//Loop through files to call downloads
int totalMissing = numberOfMissingVids; //missing vids is updated each successful download, whereas we want this to remain showing the total
int missingCounter = 1;
for (int i = 0; i < numberOfVideos; i++) {
if (!videos[i].Downloaded) {
Debug.Log($"Downloading {videos[i].FileName} from {videos[i].OnlinePath}");
downloadStatusText.text = $"Downloading file {missingCounter} of {totalMissing}...  0%";
yield return StartCoroutine(DownloadVideo(videos[i]));
missingCounter ++;
}
}
}

IEnumerator DownloadVideo(VideoData video) {

UnityWebRequest uwr = UnityWebRequest.Get(video.OnlinePath);
uwr.SendWebRequest();

while (!uwr.isDone) {
imageIndicator.fillAmount = uwr.downloadProgress;
downloadStatusText.text = $"{downloadStatusText.text.Substring(0, downloadStatusText.text.Length-3)}{((int)(uwr.downloadProgress * 100)).ToString("00")}%";
yield return null;
}

if (uwr.result != UnityWebRequest.Result.Success) {
Debug.LogError("Download error: " + uwr.error);
downloadStatusText.text = "Download failed!";
}
else {
string savePath = Path.Combine(Application.persistentDataPath, video.FileName);
downloadStatusText.text = $"Saving {video.FileName}";
File.WriteAllBytes(savePath, uwr.downloadHandler.data);
numberOfMissingVids --;
Debug.Log($"{video.FileName} saved to {savePath}");
video.SetFinalPath(savePath);
video.SetDownloaded(true);
}

uwr.Dispose();
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post