最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How do I have multiple downloads complete sequentially while the headset is off the user's head? - Stack Overflow

programmeradmin6浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

You need to implement focus awareness

https://developers.meta/horizon/documentation/unity/unity-overlays/

发布评论

评论列表(0)

  1. 暂无评论