IEnumerator LoadingSequence() { float t0 = Time.realtimeSinceStartup; loadingScreen.Show(); yield return(new WaitForSecondsRealtime(0.5f)); System.Action startPlaying = () => { float t1 = Time.realtimeSinceStartup; loadingScreen.FadeAndHide(); voosEngine.SetIsRunning(true); GameObject.FindObjectOfType <UserMain>().FadeInAudioAfterLoading(); }; if (!IsLoadingResources()) { startPlaying(); yield break; } loadingScreen.SetCancelButton("Start Playing Anyway", () => startPlaying()); int totalDownloads = 1; int totalChunks = 1; while (IsLoadingResources()) { // We compute the # of total downloads in this weird and very approximate way, // but it's not like progress bars ever tell the truth anyway. // This is necessary because not all downloads may be immediately queueud. int downloadsRemaining = assetCache.GetNumActiveDownloads(); totalDownloads = Mathf.Max(downloadsRemaining, totalDownloads); int chunksRemaining = terrain.GetNumImportantChunksRemaining(); totalChunks = Mathf.Max(chunksRemaining, totalChunks); float progress = 1 - ((downloadsRemaining + chunksRemaining) * 1f / (totalDownloads + totalChunks)); string text = ""; if (downloadsRemaining > 0) { text += $"Loading models, {downloadsRemaining} remaining."; } if (chunksRemaining > 0) { text += $"\nGenerating terrain, {chunksRemaining} chunks remaining."; } loadingScreen.SetProgress(progress); loadingScreen.SetStatusText(text); yield return(new WaitForSecondsRealtime(0.1f)); } // One last little bit to reduce chances of people falling through the // ground.. yield return(new WaitForSecondsRealtime(0.5f)); startPlaying(); }