admin管理员组文章数量:1402842
Using unity web request I can start one download, take the quest headset off and that download will finish. It won't save or start the next download. How could I pull that off? Either by keeping the headset awake or running scripts despite the headset being turned off.
Thanks in advance
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();
}
Using unity web request I can start one download, take the quest headset off and that download will finish. It won't save or start the next download. How could I pull that off? Either by keeping the headset awake or running scripts despite the headset being turned off.
Thanks in advance
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();
}
Share
Improve this question
edited Mar 21 at 8:13
DarkBee
15.5k8 gold badges72 silver badges117 bronze badges
asked Mar 21 at 8:06
RuzzRuzz
11 bronze badge
3
- Could you indicate what precise error you get ? – XouDo Commented Mar 21 at 10:44
- @XouDo I don't think any. As I understand when the user puts down the headset then unity code isn't executed so no further requests will be started and results not be handled until the user puts the device back on – derHugo Commented Mar 21 at 10:48
- 1 Found this very old open ended thread communityforums.atmeta/t5/Unity-Development/… might be worth a shot .. – derHugo Commented Mar 21 at 10:50
1 Answer
Reset to default 0You need to implement focus awareness
https://developers.meta/horizon/documentation/unity/unity-overlays/
本文标签:
版权声明:本文标题:c# - How do I have multiple downloads complete sequentially while the headset is off the user's head? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744367060a2602831.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论